init
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/venv/
|
||||||
|
.idea/
|
||||||
41
main.py
Normal file
41
main.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
from pyparsing import (Suppress, Keyword, Word, alphas, alphanums, Combine,
|
||||||
|
OneOrMore, quotedString, removeQuotes, Group, ZeroOrMore, SkipTo, LineEnd, Regex)
|
||||||
|
import pprint
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
LBRACE, RBRACE, EQ = map(Suppress, "{}=")
|
||||||
|
|
||||||
|
DEFINE = Keyword("define")
|
||||||
|
|
||||||
|
filter_comments = Regex(r"#.*")
|
||||||
|
filter_comments = filter_comments.suppress()
|
||||||
|
|
||||||
|
ident = Word(alphas, alphanums)
|
||||||
|
dottedIdent = Combine(ident + OneOrMore("_" + ident))
|
||||||
|
|
||||||
|
value = Regex('.*')
|
||||||
|
propertyDefn = Group((dottedIdent | ident)("name") + value("value"))
|
||||||
|
|
||||||
|
objectBodyDefn = Group(ZeroOrMore(propertyDefn("properties*")))
|
||||||
|
|
||||||
|
objectDefn = Group(DEFINE + ident("type") + LBRACE + objectBodyDefn("body") + RBRACE)
|
||||||
|
|
||||||
|
parser = ZeroOrMore(objectDefn)
|
||||||
|
|
||||||
|
config = defaultdict(defaultdict)
|
||||||
|
for obj in parser.parseFile('objects.cache'):
|
||||||
|
if obj.body.properties:
|
||||||
|
o = defaultdict(defaultdict)
|
||||||
|
for prop in obj.body.properties:
|
||||||
|
o[prop.name] = prop.value
|
||||||
|
if obj.type in ('service', 'host'):
|
||||||
|
config[obj.type][o["host_name"]] = o
|
||||||
|
if obj.type == 'timeperiod':
|
||||||
|
config[obj.type][o["timeperiod_name"]] = o
|
||||||
|
if obj.type == 'command':
|
||||||
|
config[obj.type][o["command_name"]] = o
|
||||||
|
else:
|
||||||
|
print(' ', '<none>')
|
||||||
|
print()
|
||||||
|
|
||||||
|
pprint.pp(config)
|
||||||
7651
objects.cache
Normal file
7651
objects.cache
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user