I'm trying to write a wrapper for an icinga2 instance. The objets inside the config files look like this;
object object_type "object_name" {
some_property = "some_value"
}
example;
object Host "server1" {
import "generic-host"
address = "192.168.0.1"
vars.os = "Linux"
}
object Host "server2" {
import "generic-host"
address = "192.168.0.2"
vars.os = "Linux"
}
I'm looking to do something like:
icinga = icinga("/etc/icinga2/conf.d/hosts.conf")
print icinga.hosts_list()
icinga.hosts_add("server3","192.168.0.3")
icinga.hosts_remove("server1")
So I tried using pynag, something like;
nc = Config('/etc/icinga2/conf.d/hosts.conf')
nc.parse()
print nc.get_host('server1')
but I'm getting;
File "./icinga.py", line 51, in <module>
print nc.get_host('server1')
File "/Library/Python/2.7/site-packages/pynag/Parsers/__init__.py", line 1259, in get_host
return self.get_object('host', object_name, user_key=user_key)
File "/Library/Python/2.7/site-packages/pynag/Parsers/__init__.py", line 1238, in get_object
for item in self.data['all_%s' % object_type]:
KeyError: 'all_host'
Is there an easy way to work with this kind of formar?