This module provides a high level Object-Oriented wrapper around pynag.Parsers.config.
Example:
>>> from pynag.Model import Service, Host
>>>
>>> all_services = Service.objects.all
>>> my_service = all_services[0]
>>> print my_service.host_name
localhost
>>>
>>> example_host = Host.objects.filter(host_name="host.example.com")
>>> canadian_hosts = Host.objects.filter(host_name__endswith=".ca")
>>>
>>> for i in canadian_hosts:
... i.alias = "this host is located in Canada"
... i.save()
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
This is the %s attribute for object definition
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Delete this contact and optionally remove references in groups and escalations
Works like ObjectDefinition.delete() except:
This is the %s attribute for object definition
Get a list of all Contactgroup that are hooked to this contact
Get a list of all Host that are hooked to this Contact
Get a list of all Service that are hooked to this Contact
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Bases: pynag.Model.ObjectDefinition
Adds one specific contact to this contactgroup.
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Delete this contactgroup and optionally remove references in hosts/services
Works like ObjectDefinition.delete() except:
Returns a list of every Contactgroup that is a member of this Contactgroup
Returns a list of every Contact that is a member of this Contactgroup
Return every Host that belongs to this contactgroup
Return every Host that belongs to this contactgroup
This is the %s attribute for object definition
Remove one specific contact from this contactgroup
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Add host to a hostgroup
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Same as ObjectDefinition.copy() except can recursively copy services
Delete this host and optionally its services
Works like ObjectDefinition.delete() except for:
This is the %s attribute for object definition
Put this object in a schedule downtime.
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Same as Service.get_current_status()
Returns a Command object as defined by check_command attribute
Raises KeyError if check_command is not found or not defined.
Returns a list of all Contactgroup that belong to this Host
Returns a list of all Contact that belong to this Host
Returns a list of all Hostgroup that belong to this Host
Get all objects that depend on this one via “parents” attribute
Get all objects this one depends on via “parents” attribute
Returns a list of all Service that belong to this Host
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Removes host from specified hostgroup
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
Adds host to this group. Behaves like Hostgroup._add_member_to_group
This is the %s attribute for object definition
Delete this hostgroup and optionally remove references in hosts and services
Works like ObjectDefinition.delete() except:
Put every host and service in this hostgroup in a schedule downtime.
Returns a list of every Hostgroup that is a member of this Hostgroup
Returns a list of all Host that belong to this hostgroup
Returns a list of all Service that belong to this hostgroup
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Remove host from this group. Behaves like Hostgroup._remove_member_from_group
alias of HostEscalation
Bases: object
Holds one instance of one particular Object definition
>>> objects = ObjectDefinition.objects.all
>>> my_object = ObjectDefinition( dict )
Convenient way to append value to an attribute with a comma seperated value
>>> myservice = Service()
>>> myservice.attribute_appendfield(attribute_name="contact_groups", value="alladmins")
>>> myservice.contact_groups
'+alladmins'
>>> myservice.attribute_appendfield(attribute_name="contact_groups", value='webmasters')
>>> print myservice.contact_groups
+alladmins,webmasters
Check if the attribute is empty
Parameters: | attribute_name – A attribute such as host_name |
---|---|
Returns: | True or False |
Convenient way to remove value to an attribute with a comma seperated value
>>> myservice = Service()
>>> myservice.contact_groups = "+alladmins,localadmins"
>>> myservice.attribute_removefield(attribute_name="contact_groups", value='localadmins')
>>> print myservice.contact_groups
+alladmins
>>> myservice.attribute_removefield(attribute_name="contact_groups", value="alladmins")
>>> print myservice.contact_groups
None
Convenient way to replace field within an attribute with a comma seperated value
>>> myservice = Service()
>>> myservice.contact_groups = "+alladmins,localadmins"
>>> myservice.attribute_replacefield(attribute_name="contact_groups", old_value='localadmins', new_value="webmasters")
>>> print myservice.contact_groups
+alladmins,webmasters
Copies this object definition with any unsaved changes to a new configuration object
myhost = Host.objects.get_by_shortname(‘myhost.example.com’)
# Copy this host to a new one myhost.copy( host_name=”newhost.example.com”, address=”127.0.0.1”)
Deletes this object definition from its configuration files.
Parameters: |
|
---|
self.get(x) == self[x]
Returns {macroname:macrovalue} hash map of this object’s macros
Get one attribute from our object definition
Parameters: | attribute_name – A attribute such as host_name |
---|
Returns all relevant attributes in the form of:
(attribute_name,defined_value,inherited_value)
Returns a human friendly string describing current object.
It will try the following in order: * return self.name (get the generic name) * return self get_shortname() * return “Untitled $object_type”
Get a list of all objects that inherit this object via “use” attribute
Parameters: | recursive – If true, include grandchildren as well |
---|---|
Returns: | A list of ObjectDefinition objects |
Return a string of this objects check_command with all macros (i.e. $HOSTADDR$) resolved
Get this objects notifications with all macros (i.e. $HOSTADDR$) resolved
Parameters: |
|
---|---|
Returns: | string of this objects notifications |
Get all objects that this one inherits via “use” attribute
Get name of the config file which defines this object
Return a unique ID for this object
Take macroname (e.g. $USER1$) and return its actual value
macroname – Macro that is to be resolved. For example $HOSTADDRESS$ host_name – Optionally specify host (use this for services that
– don’t define host specifically for example ones that only – define hostgroups
Out-dated, use get_effective_parents instead. Kept here for backwards compatibility
Returns a list of ObjectDefinition that depend on this object
Object can “depend” on another by a ‘use’ or ‘host_name’ or similar attribute
Returns shortname of an object in string format.
For the confused, nagios documentation refers to shortnames usually as <object_type>_name.
Returns None if no attribute can be found to use as a shortname
Get a suitable configuration filename to store this object in
Returns: | filename, eg str(‘/etc/nagios/pynag/templates/hosts.cfg’) |
---|
Same as key in self
Returns true if any attributes has been changed on this object, and therefore it needs saving
Returns true if object is enabled (registered)
Move this object definition to a new file. It will be deleted from current file.
>>> self.copy(filename=filename)
>>> self.delete()
Returns: | The new object definition |
---|
This is the %s attribute for object definition
This is the %s attribute for object definition
Re-applies templates to this object (handy when you have changed the use attribute
Run the check_command defined by this service. Returns return_code,stdout,stderr
Set (but does not save) one attribute in our object
Parameters: |
|
---|
Set name of the config file which this object will be written to on next save.
Update a macro (custom variable) like $ARG1$ intelligently
Returns: None
Notes: You are responsible for calling .save() after modifying the object
>>> s = Service()
>>> s.check_command = 'okc-execute!arg1!arg2'
>>> s.set_macro('$ARG1$', 'modified1')
>>> s.check_command
'okc-execute!modified1!arg2'
>>> s.set_macro('$ARG5$', 'modified5')
>>> s.check_command
'okc-execute!modified1!arg2!!!modified5'
>>> s.set_macro('$_SERVICE_TEST$', 'test')
>>> s['__TEST']
'test'
Short for self[‘register’] = 0 ; self.save()
This is the %s attribute for object definition
Bases: object
This class is a wrapper around pynag.Parsers.config. Is responsible for fetching dict objects from config.data and turning into high ObjectDefinition objects
Returns all objects that match the selected filter
Example:
>>> Service.objects.filter(host_name='examplehost.example.com')
>>> Service.objects.filter(host_name='examplehost.example.com',
... service_description='Ping')
>>> Service.objects.filter(host_name=None,register='1')
>>> Host.objects.filter(host_name__startswith='exampleh')
>>> Service.objects.filter(host_name__endswith='example.com')
>>> Contactgroup.objects.filter(host_name__contains='dba')
>>> Host.objects.filter(hostgroup_name__notcontains='testservers')
>>> Service.objects.filter(name__isnot=None)
>>> Host.objects.filter(address_exists=True)
Get one specific object
Returns: | ObjectDefinition |
---|---|
Raises : | ValueError if object is not found |
Get one specific object by its object_name (i.e. name attribute)
Returns: | ObjectDefinition |
---|---|
Raises : | ValueError if object is not found |
Get one specific object by its shortname (i.e. host_name for host, etc)
Parameters: |
|
---|---|
Returns: | ObjectDefinition |
Raises : | ValueError if object is not found |
Returns a list of all discovered object types
Bases: object
Static container for objects and their respective neighbours
Runs clear() on every member attribute in ObjectRelations
Update all contactgroup relations to take into account contactgroup.contactgroup_members
Update all hostgroup relations to take into account hostgroup.hostgroup_members
If any object relations are a regular expression, then expand them into a full list
Update all servicegroup relations to take into account servicegroup.servicegroup_members
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
This is the %s attribute for object definition
Add this service to a specific servicegroup
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Put this object in a schedule downtime.
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Returns a Status object, reflecting this object status (i.e. status.dat)
Returns a Command object as defined by check_command attribute
Raises KeyError if check_command is not found or not defined.
Returns a list of all Contactgroup that belong to this Service
Returns a list of all Contact that belong to this Service
Returns a list of all Hostgroup that belong to this Service
Returns a list of all Host that belong to this Service
Returns a list of all Servicegroup that belong to this Service
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Moves a service from its original file to the same file as the first effective host
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
remove this service from a specific servicegroup
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
Adds service to this group. Behaves like _add_object_to_group(object, group)
This is the %s attribute for object definition
Put every host and service in this servicegroup in a schedule downtime.
Returns a list of every Servicegroup that is a member of this Servicegroup
Returns a list of all Service that belong to this Servicegroup
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
remove service from this group. Behaves like _remove_object_from_group(object, group)
This is the %s attribute for object definition
This is the %s attribute for object definition
Bases: pynag.Model.ObjectDefinition
This is the %s attribute for object definition
This is the %s attribute for object definition
This is the %s attribute for object definition
eventhandlers – A list of Model.EventHandlers object.
This file contains a dict object that maps Nagios Standard macronames to specific values.
i.e. macros[‘$HOSTADDR$’] should return ‘address’