Simplfy object types

master
Micke Nordin 3 years ago
parent 472667f1f1
commit 47198413e2
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257

@ -13,71 +13,14 @@ class ParserState(Enum):
class NagParse: class NagParse:
def __init__(self, config_files: list[str]): def __init__(self, config_files: list[str]):
self.m_config_files: list[str] = config_files self.m_config_files: list[str] = config_files
self.m_commands: list[NagObject] = list() self.m_objects: list[NagObject] = list()
self.m_contacts: list[NagObject] = list()
self.m_contactgroups: list[NagObject] = list()
self.m_hosts: list[NagObject] = list()
self.m_hostdependencies: list[NagObject] = list()
self.m_hostescalations: list[NagObject] = list()
self.m_hostgroups: list[NagObject] = list()
self.m_services: list[NagObject] = list()
self.m_servicedependencies: list[NagObject] = list()
self.m_serviceescalations: list[NagObject] = list()
self.m_servicegroups: list[NagObject] = list()
self.m_timeperiods: list[NagObject] = list()
for config_file in self.m_config_files: for config_file in self.m_config_files:
for object in self.parse_config(config_file): for object in self.parse_config(config_file):
match object.m_type: self.m_objects.append(object)
case NagObjectType.Command:
self.m_commands.append(object)
case NagObjectType.Contact:
self.m_contacts.append(object)
case NagObjectType.ContactGroup:
self.m_contactgroups.append(object)
case NagObjectType.Host:
self.m_hosts.append(object)
case NagObjectType.HostDependency:
self.m_hostdependencies.append(object)
case NagObjectType.HostEscalation:
self.m_hostescalations.append(object)
case NagObjectType.HostGroup:
self.m_hostgroups.append(object)
case NagObjectType.Service:
self.m_services.append(object)
case NagObjectType.ServiceDependency:
self.m_servicedependencies.append(object)
case NagObjectType.ServiceEscalation:
self.m_serviceescalations.append(object)
case NagObjectType.ServiceGroup:
self.m_servicegroups.append(object)
case NagObjectType.TimePeriod:
self.m_timeperiods.append(object)
def __str__(self): def __str__(self):
string = str() string = str()
for fragment in self.m_commands: for object in self.m_objects:
string += str(fragment) + "\n" string += str(object) + "\n"
for fragment in self.m_contacts:
string += str(fragment) + "\n"
for fragment in self.m_contactgroups:
string += str(fragment) + "\n"
for fragment in self.m_hosts:
string += str(fragment) + "\n"
for fragment in self.m_hostdependencies:
string += str(fragment) + "\n"
for fragment in self.m_hostescalations:
string += str(fragment) + "\n"
for fragment in self.m_hostgroups:
string += str(fragment) + "\n"
for fragment in self.m_services:
string += str(fragment) + "\n"
for fragment in self.m_servicedependencies:
string += str(fragment) + "\n"
for fragment in self.m_serviceescalations:
string += str(fragment) + "\n"
for fragment in self.m_servicegroups:
string += str(fragment) + "\n"
for fragment in self.m_timeperiods:
string += str(fragment) + "\n"
return string return string
def parse_config(self,config_file: str) -> list[NagObject]: def parse_config(self,config_file: str) -> list[NagObject]:

Loading…
Cancel
Save