added presets

This commit is contained in:
Eugenio Marzo
2022-12-30 11:45:13 +01:00
parent 06d7c64268
commit b72c1b897b
13 changed files with 370 additions and 67 deletions
+1 -4
View File
@@ -38,7 +38,6 @@ elseif ngx.var.request_method == "POST" and action == "set_log_regex" then
local body_data = ngx.req.get_body_data()
red:set("log_pod_regex:" .. arg['id'], body_data)
red:set("programming_mode", "0")
-- os.execute("> /var/www/html/chaoslogs-" .. arg['id'] .. ".html")
ngx.say("Regex has been set => " .. body_data)
ngx.log(ngx.ERR, "Set Regex for web log tail. log id " .. arg['id'])
return ngx.exit(ngx.status)
@@ -46,16 +45,14 @@ elseif ngx.var.request_method == "POST" and action == "set_log_regex" then
elseif ngx.var.request_method == "POST" and action == "enable_log_tail" then
local body_data = ngx.req.get_body_data()
red:set("logs_enabled:" .. arg['id'], "1")
red:expire("logs_enabled:" .. arg['id'], "10")
red:set("programming_mode", "0")
-- os.execute("> /var/www/html/chaoslogs-" .. arg['id'] .. ".html")
ngx.log(ngx.ERR, "Enable Log Tail for log id " .. arg['id'])
ngx.say("Enable Log Tail for log id " .. arg['id'])
return ngx.exit(ngx.status)
elseif ngx.var.request_method == "POST" and action == "disable_log_tail" then
-- red:set("logs_enabled:" .. arg['id'], "0")
red:set("programming_mode", "0")
-- os.execute("> /var/www/html/chaoslogs-" .. arg['id'] .. ".html")
ngx.say("Disable Log Tail for log id " .. arg['id'])
ngx.log(ngx.ERR, "Disable Log Tail for log id " .. arg['id'])
return ngx.exit(ngx.status)
+3 -2
View File
@@ -35,7 +35,7 @@ def compute_line(api_response_line, api_instance, container):
r.set(f"log:{logid}{pod.metadata.name}:{sha256log}", logrow)
r.set(f"log_time:{logid}:{pod.metadata.name}", time.time())
r.expire(f"log:{logid}:{pod.metadata.name}:{sha256log}", 60)
r.expire(f"log:{logid}:{pod.metadata.name}:{sha256log}", 10)
logging.info(f"[logid:{logid}] Phase of {pod.metadata.name} is {pod.status.phase}")
if pod.status.phase == "Succeeded" and pod.metadata.labels['approle'] == 'chaosnode':
@@ -86,6 +86,7 @@ if os.environ.get("DEV"):
logging.info("Setting env var for dev...")
r.set("log_pod_regex", '{"pod":".*", "namespace":"namespace1", "labels":".*", "annotations":".*", "containers": ".*"}')
r.set("logs_enabled:aaaa", 1)
r.expire("logs_enabled:aaaa", 10)
r.set("programming_mode", 0)
logging.info(r.get("log_pod_regex:aaaa"))
logging.info(r.get("logs_enabled:aaaa"))
@@ -135,7 +136,7 @@ while True:
logging.info(f"[logid:{logid}] Remove /var/www/html/chaoslogs-{logid}.html")
os.remove(f"/var/www/html/chaoslogs-{logid}.html")
r.set(f"log_cleaner:{logid}", "1")
r.expire(f"log_cleaner:{logid}", 60)
r.expire(f"log_cleaner:{logid}", 10)
else:
logging.info(f"[logid:{logid}] The key log_cleaner:{logid} esists. Clean /var/www/html/chaoslogs-{logid}.html is not needed")
+1
View File
@@ -46,6 +46,7 @@ red:del("log_cleaner:" .. arg['id'])
ngx.log(ngx.ERR, "[programming_mode] set logs_enabled:" .. arg['id'] .. " Redis key")
red:set("logs_enabled:" .. arg['id'], "1")
red:expire("logs_enabled:" .. arg['id'], "10")
local handle = io.popen("python3 /opt/programming_mode/start.py " .. file_name .. " " .. k8s_url)
local result = handle:read("*a")