add simple parsers && template directory
All checks were successful
/ test (push) Successful in 2m49s
All checks were successful
/ test (push) Successful in 2m49s
This commit is contained in:
parent
6b15056d47
commit
7988d852e2
7 changed files with 102 additions and 1 deletions
36
parsers/base.py
Normal file
36
parsers/base.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#!/bin/env python3
|
||||||
|
import sys
|
||||||
|
from os import listdir
|
||||||
|
from os.path import isfile, join
|
||||||
|
from debian import parse_debian
|
||||||
|
from freebsd import parse_freebsd
|
||||||
|
from freebox import parse_freebox
|
||||||
|
|
||||||
|
def find_os(content):
|
||||||
|
version = content.split("###### VERSION ######")[-1]
|
||||||
|
osystem = [line.split("=")[-1] for line in version.splitlines() if line.startswith("ID=")]
|
||||||
|
if osystem:
|
||||||
|
return osystem[0]
|
||||||
|
else:
|
||||||
|
return "freebox"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
mypath = "../oxidized/"
|
||||||
|
|
||||||
|
onlyfiles = [mypath + f for f in listdir(mypath) if isfile(join(mypath, f))]
|
||||||
|
|
||||||
|
for file in onlyfiles:
|
||||||
|
with open(file,"r") as f:
|
||||||
|
content = f.read()
|
||||||
|
current_os = find_os(content)
|
||||||
|
if "freebsd" in current_os:
|
||||||
|
parse_freebsd(content)
|
||||||
|
elif "debian" in current_os:
|
||||||
|
parse_debian(content)
|
||||||
|
else:
|
||||||
|
parse_freebox(content)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
31
parsers/debian.py
Normal file
31
parsers/debian.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/env python3
|
||||||
|
from json import loads
|
||||||
|
|
||||||
|
def parse_ip(raw_ip):
|
||||||
|
result = []
|
||||||
|
ip = loads(raw_ip)
|
||||||
|
for interface in ip:
|
||||||
|
if not interface["ifname"].startswith("br-")\
|
||||||
|
and not interface["ifname"].startswith("vet") \
|
||||||
|
and not interface["ifname"].startswith("dock") \
|
||||||
|
and interface["operstate"] != "DOWN" \
|
||||||
|
:
|
||||||
|
result.append(interface)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def parse_debian(content):
|
||||||
|
current_section = ""
|
||||||
|
result = {}
|
||||||
|
for line in content.splitlines():
|
||||||
|
if line.startswith("#####") and line.endswith("#####"):
|
||||||
|
current_section = line.replace(" ","").replace("#","").lower()
|
||||||
|
result[current_section] = ""
|
||||||
|
else:
|
||||||
|
if current_section:
|
||||||
|
result[current_section] += line
|
||||||
|
print(result["hostname"])
|
||||||
|
print(parse_ip(result["ip"]))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
8
parsers/freebox.py
Normal file
8
parsers/freebox.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/env python3
|
||||||
|
|
||||||
|
def parse_freebox(content):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
18
parsers/freebsd.py
Normal file
18
parsers/freebsd.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/env python3
|
||||||
|
|
||||||
|
def parse_freebsd(content):
|
||||||
|
current_section = ""
|
||||||
|
result = {}
|
||||||
|
for line in content.splitlines():
|
||||||
|
if line.startswith("#####") and line.endswith("#####"):
|
||||||
|
current_section = line.replace(" ","").replace("#","").lower()
|
||||||
|
result[current_section] = ""
|
||||||
|
else:
|
||||||
|
if current_section:
|
||||||
|
result[current_section] += line
|
||||||
|
from pprint import pprint
|
||||||
|
#pprint(result)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
@ -32,6 +32,7 @@ def download(domain, icon_url):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
mypath = "/var/home/mika/projects/dev/nginx-config/conf.d/"
|
mypath = "/var/home/mika/projects/dev/nginx-config/conf.d/"
|
||||||
|
mypath = "../nginx-config/conf.d/"
|
||||||
|
|
||||||
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
|
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
|
||||||
url = port = ip = ""
|
url = port = ip = ""
|
||||||
|
@ -55,7 +56,7 @@ def main():
|
||||||
result[url] = {
|
result[url] = {
|
||||||
"dest":ip,
|
"dest":ip,
|
||||||
"port":port,
|
"port":port,
|
||||||
"icon": download(url, find_icon(url))
|
"icon": find_icon(url)
|
||||||
}
|
}
|
||||||
#print(dict(sorted(result.items(), key=lambda item: item[1])))
|
#print(dict(sorted(result.items(), key=lambda item: item[1])))
|
||||||
|
|
||||||
|
|
4
template/base.rst.j2
Normal file
4
template/base.rst.j2
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{{ "=" * (host|length) }}
|
||||||
|
{{ host }}
|
||||||
|
{{ "=" * (host|length) }}
|
||||||
|
|
3
template/freebsd.rst.j2
Normal file
3
template/freebsd.rst.j2
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{% include "base.rst.j2" %}
|
||||||
|
services
|
||||||
|
--------
|
Loading…
Add table
Reference in a new issue