feat: push directly to prometheus
This commit is contained in:
+4
-12
@@ -1,7 +1,7 @@
|
||||
import shlex
|
||||
|
||||
|
||||
def tokenize(text):
|
||||
def tokenize(text) -> list:
|
||||
lexer = shlex.shlex(text, posix=True)
|
||||
lexer.whitespace_split = True
|
||||
lexer.commenters = "#"
|
||||
@@ -24,12 +24,9 @@ def parse_sites_imports(text):
|
||||
if i + 1 < len(tokens) and tokens[i + 1] == "{":
|
||||
if depth == 0:
|
||||
sites = [s.strip() for s in tok.split(",")]
|
||||
|
||||
for s in sites:
|
||||
result.setdefault(s, [])
|
||||
|
||||
current_site = sites
|
||||
|
||||
depth += 1
|
||||
i += 2
|
||||
continue
|
||||
@@ -48,13 +45,11 @@ def parse_sites_imports(text):
|
||||
result[site].append(name)
|
||||
i += 2
|
||||
continue
|
||||
|
||||
i += 1
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def filter_globals_out(data):
|
||||
def filter_globals_out(data) -> dict:
|
||||
import re
|
||||
|
||||
ret = dict()
|
||||
@@ -65,11 +60,8 @@ def filter_globals_out(data):
|
||||
return ret
|
||||
|
||||
|
||||
def parse(data):
|
||||
data = parse_sites_imports(data)
|
||||
data = filter_globals_out(data)
|
||||
return data
|
||||
|
||||
def parse(caddy_string) -> dict[str, list[str]]:
|
||||
return filter_globals_out(parse_sites_imports(caddy_string))
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("Caddyfile") as f:
|
||||
|
||||
Reference in New Issue
Block a user