Model Package

Model Package

This module provides a high level Object-Oriented wrapper around pynag.Parsers.

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() 
class pynag.Model.Command(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

command_line

This is the %s attribute for object definition

command_name

This is the %s attribute for object definition

object_type = 'command'
objects = <pynag.Model.ObjectFetcher object>
rename(shortname)

Rename this command, and reconfigure all related objects

class pynag.Model.Contact(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

add_to_contactgroup(contactgroup)
address

This is the %s attribute for object definition

alias

This is the %s attribute for object definition

can_submit_commands

This is the %s attribute for object definition

contact_name

This is the %s attribute for object definition

contactgroups

This is the %s attribute for object definition

delete(recursive=False, cleanup_related_items=True)

Delete this contact and optionally remove references in groups and escalations

Works like ObjectDefinition.delete() except:

Arguments:
cleanup_related_items – If True, remove all references to this contact in contactgroups and escalations recursive – If True, remove escalations/dependencies that rely on this (and only this) contact
email

This is the %s attribute for object definition

get_effective_contactgroups()

Get a list of all Contactgroup that are hooked to this contact

get_effective_hosts()

Get a list of all Host that are hooked to this Contact

get_effective_services()

Get a list of all Service that are hooked to this Contact

host_notification_commands

This is the %s attribute for object definition

host_notification_options

This is the %s attribute for object definition

host_notification_period

This is the %s attribute for object definition

host_notifications_enabled

This is the %s attribute for object definition

object_type = 'contact'
objects = <pynag.Model.ObjectFetcher object>
pager

This is the %s attribute for object definition

remove_from_contactgroup(contactgroup)
rename(shortname)

Renames this object, and triggers a change in related items as well.

Args:
shortname: New name for this object
Returns:
None
retain_nonstatus_information

This is the %s attribute for object definition

retain_status_information

This is the %s attribute for object definition

service_notification_commands

This is the %s attribute for object definition

service_notification_options

This is the %s attribute for object definition

service_notification_period

This is the %s attribute for object definition

service_notifications_enabled

This is the %s attribute for object definition

class pynag.Model.Contactgroup(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

add_contact(contact_name)

Adds one specific contact to this contactgroup.

alias

This is the %s attribute for object definition

contactgroup_members

This is the %s attribute for object definition

contactgroup_name

This is the %s attribute for object definition

delete(recursive=False, cleanup_related_items=True)

Delete this contactgroup and optionally remove references in hosts/services

Works like ObjectDefinition.delete() except:

Arguments:
cleanup_related_items – If True, remove all references to this group in hosts,services,etc. recursive – If True, remove dependant escalations.
get_effective_contactgroups()

Returns a list of every Contactgroup that is a member of this Contactgroup

get_effective_contacts()

Returns a list of every Contact that is a member of this Contactgroup

get_effective_hosts()

Return every Host that belongs to this contactgroup

get_effective_services()

Return every Host that belongs to this contactgroup

members

This is the %s attribute for object definition

object_type = 'contactgroup'
objects = <pynag.Model.ObjectFetcher object>
remove_contact(contact_name)

Remove one specific contact from this contactgroup

rename(shortname)

Renames this object, and triggers a change in related items as well.

Args:
shortname: New name for this object
Returns:
None
class pynag.Model.Host(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

2d_coords

This is the %s attribute for object definition

3d_coords

This is the %s attribute for object definition

acknowledge(sticky=1, notify=1, persistent=0, author='pynag', comment='acknowledged by pynag', recursive=False, timestamp=None)
action_url

This is the %s attribute for object definition

active_checks_enabled

This is the %s attribute for object definition

add_to_contactgroup(contactgroup)
add_to_hostgroup(hostgroup_name)

Add host to a hostgroup

address

This is the %s attribute for object definition

alias

This is the %s attribute for object definition

check_command

This is the %s attribute for object definition

check_freshness

This is the %s attribute for object definition

check_interval

This is the %s attribute for object definition

check_period

This is the %s attribute for object definition

contact_groups

This is the %s attribute for object definition

contacts

This is the %s attribute for object definition

copy(recursive=False, filename=None, **args)

Same as ObjectDefinition.copy() except can recursively copy services

delete(recursive=False, cleanup_related_items=True)

Delete this host and optionally its services

Works like ObjectDefinition.delete() except for:

Arguments:
cleanup_related_items – If True, remove references found in hostgroups and escalations recursive – If True, also delete all services of this host
display_name

This is the %s attribute for object definition

downtime(start_time=None, end_time=None, trigger_id=0, duration=7200, author=None, comment='Downtime scheduled by pynag', recursive=False)

Put this object in a schedule downtime.

Arguments:
start_time – When downtime should start. If None, use time.time() (now) end_time – When scheduled downtime should end. If None use start_time + duration duration – Alternative to end_time, downtime lasts for duration seconds. Default 7200 seconds. trigger_id – trigger_id>0 means that this downtime should trigger another downtime with trigger_id. author – name of the contact scheduling downtime. If None, use current system user comment – Comment that will be put in with the downtime recursive – Also schedule same downtime for all service of this host.
Returns:
None because commands sent to nagios have no return values
Raises:
ModelError if this does not look an active object.
event_handler

This is the %s attribute for object definition

event_handler_enabled

This is the %s attribute for object definition

first_notification_delay

This is the %s attribute for object definition

flap_detection_enabled

This is the %s attribute for object definition

flap_detection_options

This is the %s attribute for object definition

freshness_threshold

This is the %s attribute for object definition

get_current_status()

Returns a dictionary with status data information for this object

get_effective_check_command()

Returns a Command object as defined by check_command attribute

Raises KeyError if check_command is not found or not defined.

get_effective_contact_groups()

Returns a list of all Contactgroup that belong to this Host

get_effective_contacts()

Returns a list of all Contact that belong to this Host

get_effective_hostgroups()

Returns a list of all Hostgroup that belong to this Host

get_effective_network_children(recursive=False)

Get all objects that depend on this one via “parents” attribute

Arguments:
recursive - If true include grandchildren in list to be returned
Returns:
a list of ObjectDefinition objects
get_effective_network_parents(recursive=False)

Get all objects this one depends on via “parents” attribute

Arguments:
recursive - If true include grandparents in list to be returned
Returns:
a list of ObjectDefinition objects
get_effective_services()

Returns a list of all Service that belong to this Host

high_flap_threshold

This is the %s attribute for object definition

host_name

This is the %s attribute for object definition

hostgroups

This is the %s attribute for object definition

icon_image

This is the %s attribute for object definition

icon_image_alt

This is the %s attribute for object definition

initial_state

This is the %s attribute for object definition

low_flap_threshold

This is the %s attribute for object definition

max_check_attempts

This is the %s attribute for object definition

notes

This is the %s attribute for object definition

notes_url

This is the %s attribute for object definition

notification_interval

This is the %s attribute for object definition

notification_options

This is the %s attribute for object definition

notification_period

This is the %s attribute for object definition

notifications_enabled

This is the %s attribute for object definition

object_type = 'host'
objects = <pynag.Model.ObjectFetcher object>
obsess_over_host

This is the %s attribute for object definition

parents

This is the %s attribute for object definition

passive_checks_enabled

This is the %s attribute for object definition

process_perf_data

This is the %s attribute for object definition

remove_from_contactgroup(contactgroup)
remove_from_hostgroup(hostgroup_name)

Removes host from specified hostgroup

rename(shortname)

Rename this host, and modify related objects

retain_nonstatus_information

This is the %s attribute for object definition

retain_status_information

This is the %s attribute for object definition

retry_interval

This is the %s attribute for object definition

stalking_options

This is the %s attribute for object definition

statusmap_image

This is the %s attribute for object definition

vrml_image

This is the %s attribute for object definition

class pynag.Model.HostDependency(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

dependency_period

This is the %s attribute for object definition

dependent_host_name

This is the %s attribute for object definition

dependent_hostgroup_name

This is the %s attribute for object definition

execution_failure_criteria

This is the %s attribute for object definition

host_name

This is the %s attribute for object definition

hostgroup_name

This is the %s attribute for object definition

inherits_parent

This is the %s attribute for object definition

notification_failure_criteria

This is the %s attribute for object definition

object_type = 'hostdependency'
objects = <pynag.Model.ObjectFetcher object>
class pynag.Model.HostEscalation(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

contact_groups

This is the %s attribute for object definition

contacts

This is the %s attribute for object definition

escalation_options

This is the %s attribute for object definition

escalation_period

This is the %s attribute for object definition

first_notification

This is the %s attribute for object definition

host_name

This is the %s attribute for object definition

hostgroup_name

This is the %s attribute for object definition

last_notification

This is the %s attribute for object definition

notification_interval

This is the %s attribute for object definition

object_type = 'hostescalation'
objects = <pynag.Model.ObjectFetcher object>
class pynag.Model.Hostgroup(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

action_url

This is the %s attribute for object definition

add_host(host_name)

Adds host to this group. Behaves like Hostgroup._add_member_to_group

alias

This is the %s attribute for object definition

delete(recursive=False, cleanup_related_items=True)

Delete this hostgroup and optionally remove references in hosts and services

Works like ObjectDefinition.delete() except:

Arguments:
cleanup_related_items – If True, remove all references to this group in hosts/services,escalations,etc recursive – If True, remove services and escalations that bind to this (and only this) hostgroup
downtime(start_time=None, end_time=None, trigger_id=0, duration=7200, author=None, comment='Downtime scheduled by pynag', recursive=False)

Put every host and service in this hostgroup in a schedule downtime.

Arguments:
start_time – When downtime should start. If None, use time.time() (now) end_time – When scheduled downtime should end. If None use start_time + duration duration – Alternative to end_time, downtime lasts for duration seconds. Default 7200 seconds. trigger_id – trigger_id>0 means that this downtime should trigger another downtime with trigger_id. author – name of the contact scheduling downtime. If None, use current system user comment – Comment that will be put in with the downtime recursive – For compatibility with other downtime commands, recursive is always assumed to be true
Returns:
None because commands sent to nagios have no return values
Raises:
ModelError if this does not look an active object.
get_effective_hostgroups()

Returns a list of every Hostgroup that is a member of this Hostgroup

get_effective_hosts()

Returns a list of all Host that belong to this hostgroup

get_effective_services()

Returns a list of all Service that belong to this hostgroup

hostgroup_members

This is the %s attribute for object definition

hostgroup_name

This is the %s attribute for object definition

members

This is the %s attribute for object definition

notes

This is the %s attribute for object definition

notes_url

This is the %s attribute for object definition

object_type = 'hostgroup'
objects = <pynag.Model.ObjectFetcher object>
remove_host(host_name)

Remove host from this group. Behaves like Hostgroup._remove_member_from_group

rename(shortname)

Rename this hostgroup, and modify hosts if required

exception pynag.Model.InvalidMacro(message, errorcode=None, errorstring=None, *args, **kwargs)

Bases: pynag.Model.ModelError

Raised when a method is inputted with an invalid macro.

exception pynag.Model.ModelError(message, errorcode=None, errorstring=None, *args, **kwargs)

Bases: pynag.errors.PynagError

Base class for errors in this module.

pynag.Model.Object

alias of HostEscalation

class pynag.Model.ObjectDefinition(item=None, filename=None, **kwargs)

Bases: object

Holds one instance of one particular Object definition

Example:
>>> objects = ObjectDefinition.objects.all
>>> my_object = ObjectDefinition( dict ) 
attribute_appendfield(attribute_name, value)

Convenient way to append value to an attribute with a comma seperated value

Example:
>>> 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
attribute_is_empty(attribute_name)

Check if the attribute is empty

Parameters:attribute_name – A attribute such as host_name
Returns:True or False
attribute_removefield(attribute_name, value)

Convenient way to remove value to an attribute with a comma seperated value

Example:
>>> 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
attribute_replacefield(attribute_name, old_value, new_value)

Convenient way to replace field within an attribute with a comma seperated value

Example:
>>> 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
copy(recursive=False, filename=None, **args)

Copies this object definition with any unsaved changes to a new configuration object

Arguments:
filename: If specified, new object will be saved in this file. recursive: If true, also find any related children objects and copy those **args: Any argument will be treated a modified attribute in the new definition.
Examples:

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”)

# Copy this host and all its services:
myhost.copy(recursive=True, host_name=”newhost.example.com”, address=”127.0.0.1”)
Returns:
  • A copy of the new ObjectDefinition
  • A list of all copies objects if recursive is True
delete(recursive=False, cleanup_related_items=True)

Deletes this object definition from its configuration files.

Parameters:
  • recursive – If True, look for items that depend on this object and delete them as well (for example, if you delete a host, delete all its services as well)
  • cleanup_related_items – If True, look for related items and remove references to this one. (for example, if you delete a host, remove its name from all hostgroup.members entries)
get(value, default=None)

self.get(x) == self[x]

get_all_macros()

Returns {macroname:macrovalue} hash map of this object’s macros

get_attribute(attribute_name)

Get one attribute from our object definition

Parameters:attribute_name – A attribute such as host_name
get_attribute_tuple()

Returns all relevant attributes in the form of:

(attribute_name,defined_value,inherited_value)

get_description()

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_effective_children(recursive=False)

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
get_effective_command_line(host_name=None)

Return a string of this objects check_command with all macros (i.e. $HOSTADDR$) resolved

get_effective_notification_command_line(host_name=None, contact_name=None)

Get this objects notifications with all macros (i.e. $HOSTADDR$) resolved

Parameters:
  • host_name – Simulate notification using this host. If None: Use first valid host (used for services)
  • contact_name – Simulate notification for this contact. If None: use first valid contact for the service
Returns:

string of this objects notifications

get_effective_parents(recursive=False, cache_only=False)

Get all objects that this one inherits via “use” attribute

Arguments:
recursive - If true include grandparents in list to be returned
Returns:
a list of ObjectDefinition objects
get_filename()

Get name of the config file which defines this object

get_id()

Return a unique ID for this object

get_macro(macroname, host_name=None, contact_name=None)

Take macroname (e.g. $USER1$) and return its actual value

Arguments:

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
Returns:
(str) Actual value of the macro. For example “$HOSTADDRESS$” becomes “127.0.0.1”
get_parents()

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:
List of ObjectDefinition objects
get_shortname()

Returns shortname of an object in string format.

For the confused, nagios documentation refers to shortnames usually as <object_type>_name.

  • In case of Host it returns host_name
  • In case of Command it returns command_name
  • etc
  • Special case for services it returns “host_name/service_description”

Returns None if no attribute can be found to use as a shortname

get_suggested_filename()

Get a suitable configuration filename to store this object in

Returns:filename, eg str(‘/etc/nagios/pynag/templates/hosts.cfg’)
has_key(key)

Same as key in self

is_defined(attribute_name)

Returns True if attribute_name is defined in this object

is_dirty()

Returns true if any attributes has been changed on this object, and therefore it needs saving

is_registered()

Returns true if object is enabled (registered)

items()
keys()
move(filename)

Move this object definition to a new file. It will be deleted from current file.

This is the same as running:
>>> self.copy(filename=filename) 
>>> self.delete() 
Returns:The new object definition
name

This is the %s attribute for object definition

object_type = None
objects = <pynag.Model.ObjectFetcher object>
register

This is the %s attribute for object definition

reload_object()

Re-applies templates to this object (handy when you have changed the use attribute

rename(shortname)

Change the shortname of this object

Most objects that inherit this one, should also be responsible for updating related objects about the rename.

Args:
shortname: New name for this object
Returns:
None
rewrite(*args, **kw)
run_check_command(host_name=None)

Run the check_command defined by this service. Returns return_code,stdout,stderr

save(*args, **kw)
set_attribute(attribute_name, attribute_value)

Set (but does not save) one attribute in our object

Parameters:
  • attribute_name – A attribute such as host_name
  • attribute_value – The value you would like to set
set_filename(filename)

Set name of the config file which this object will be written to on next save.

set_macro(macroname, new_value)

Update a macro (custom variable) like $ARG1$ intelligently

Returns: None

Notes: You are responsible for calling .save() after modifying the object

Examples:
>>> 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'
unregister(recursive=True)

Short for self[‘register’] = 0 ; self.save()

use

This is the %s attribute for object definition

class pynag.Model.ObjectFetcher(object_type)

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

Internal variables:
  • _cached_objects = List of every ObjectDefinition
  • _cached_id[o.get_id()] = o
  • _cached_shortnames[o.object_type][o.get_shortname()] = o
  • _cached_names[o.object_type][o.name] = o
  • _cached_object_type[o.object_type].append( o )
all
filter(**kwargs)

Returns all objects that match the selected filter

Example:

Get all services where host_name is examplehost.example.com
>>> Service.objects.filter(host_name='examplehost.example.com') 
Get service with host_name=examplehost.example.com and service_description=’Ping’
>>> Service.objects.filter(host_name='examplehost.example.com',
...                        service_description='Ping') 
Get all services that are registered but without a host_name
>>> Service.objects.filter(host_name=None,register='1') 
Get all hosts that start with ‘exampleh’
>>> Host.objects.filter(host_name__startswith='exampleh') 
Get all hosts that end with ‘example.com’
>>> Service.objects.filter(host_name__endswith='example.com') 
Get all contactgroups that contain ‘dba’
>>> Contactgroup.objects.filter(host_name__contains='dba') 
Get all hosts that are not in the ‘testservers’ hostgroup
>>> Host.objects.filter(hostgroup_name__notcontains='testservers') 
Get all services with non-empty name
>>> Service.objects.filter(name__isnot=None) 
Get all hosts that have an address:
>>> Host.objects.filter(address_exists=True) 
get_all(*args, **kw)
get_by_id(id, cache_only=False)

Get one specific object

Returns:ObjectDefinition
Raises:ValueError if object is not found
get_by_name(object_name, cache_only=False)

Get one specific object by its object_name (i.e. name attribute)

Returns:ObjectDefinition
Raises:ValueError if object is not found
get_by_shortname(shortname, cache_only=False)

Get one specific object by its shortname (i.e. host_name for host, etc)

Parameters:
  • shortname – shortname of the object. i.e. host_name, command_name, etc.
  • cache_only – If True, dont check if configuration files have changed since last parse
Returns:

ObjectDefinition

Raises:

ValueError if object is not found

get_object_types()

Returns a list of all discovered object types

needs_reload(*args, **kw)
reload_cache(*args, **kw)
class pynag.Model.ObjectRelations

Bases: object

Static container for objects and their respective neighbours

command_host = defaultdict(<type 'set'>, {})
command_service = defaultdict(<type 'set'>, {})
contact_contactgroups = defaultdict(<type 'set'>, {})
contact_hosts = defaultdict(<type 'set'>, {})
contact_services = defaultdict(<type 'set'>, {})
contactgroup_contactgroups = defaultdict(<type 'set'>, {})
contactgroup_contacts = defaultdict(<type 'set'>, {})
contactgroup_hosts = defaultdict(<type 'set'>, {})
contactgroup_services = defaultdict(<type 'set'>, {})
contactgroup_subgroups = defaultdict(<type 'set'>, {})
host_contact_groups = defaultdict(<type 'set'>, {})
host_contacts = defaultdict(<type 'set'>, {})
host_hostgroups = defaultdict(<type 'set'>, {})
host_services = defaultdict(<type 'set'>, {})
hostgroup_hostgroups = defaultdict(<type 'set'>, {})
hostgroup_hosts = defaultdict(<type 'set'>, {})
hostgroup_services = defaultdict(<type 'set'>, {})
hostgroup_subgroups = defaultdict(<type 'set'>, {})
static reset()

Runs clear() on every member attribute in ObjectRelations

static resolve_contactgroups()

Update all contactgroup relations to take into account contactgroup.contactgroup_members

static resolve_hostgroups()

Update all hostgroup relations to take into account hostgroup.hostgroup_members

static resolve_regex()

If any object relations are a regular expression, then expand them into a full list

static resolve_servicegroups()

Update all servicegroup relations to take into account servicegroup.servicegroup_members

service_contact_groups = defaultdict(<type 'set'>, {})
service_contacts = defaultdict(<type 'set'>, {})
service_hostgroups = defaultdict(<type 'set'>, {})
service_hosts = defaultdict(<type 'set'>, {})
service_servicegroups = defaultdict(<type 'set'>, {})
servicegroup_members = defaultdict(<type 'set'>, {})
servicegroup_servicegroups = defaultdict(<type 'set'>, {})
servicegroup_services = defaultdict(<type 'set'>, {})
servicegroup_subgroups = defaultdict(<type 'set'>, {})
use = defaultdict(<function <lambda> at 0x7f8cd80e9050>, {})
class pynag.Model.Service(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

acknowledge(sticky=1, notify=1, persistent=0, author='pynag', comment='acknowledged by pynag', timestamp=None)
action_url

This is the %s attribute for object definition

active_checks_enabled

This is the %s attribute for object definition

add_to_contactgroup(contactgroup)
add_to_servicegroup(servicegroup_name)

Add this service to a specific servicegroup

check_command

This is the %s attribute for object definition

check_freshness

This is the %s attribute for object definition

check_interval

This is the %s attribute for object definition

check_period

This is the %s attribute for object definition

contact_groups

This is the %s attribute for object definition

contacts

This is the %s attribute for object definition

display_name

This is the %s attribute for object definition

downtime(start_time=None, end_time=None, trigger_id=0, duration=7200, author=None, comment='Downtime scheduled by pynag', recursive=False)

Put this object in a schedule downtime.

Arguments:
start_time – When downtime should start. If None, use time.time() (now) end_time – When scheduled downtime should end. If None use start_time + duration duration – Alternative to end_time, downtime lasts for duration seconds. Default 7200 seconds. trigger_id – trigger_id>0 means that this downtime should trigger another downtime with trigger_id. author – name of the contact scheduling downtime. If None, use current system user comment – Comment that will be put in with the downtime recursive – Here for compatibility. Has no effect on a service.
Returns:
None because commands sent to nagios have no return values
Raises:
ModelError if this does not look an active object.
event_handler

This is the %s attribute for object definition

event_handler_enabled

This is the %s attribute for object definition

first_notification_delay

This is the %s attribute for object definition

flap_detection_enabled

This is the %s attribute for object definition

flap_detection_options

This is the %s attribute for object definition

freshness_threshold

This is the %s attribute for object definition

get_current_status()

Returns a dictionary with status data information for this object

get_effective_check_command()

Returns a Command object as defined by check_command attribute

Raises KeyError if check_command is not found or not defined.

get_effective_contact_groups()

Returns a list of all Contactgroup that belong to this Service

get_effective_contacts()

Returns a list of all Contact that belong to this Service

get_effective_hostgroups()

Returns a list of all Hostgroup that belong to this Service

get_effective_hosts()

Returns a list of all Host that belong to this Service

get_effective_servicegroups()

Returns a list of all Servicegroup that belong to this Service

get_shortname()
high_flap_threshold

This is the %s attribute for object definition

host_name

This is the %s attribute for object definition

hostgroup_name

This is the %s attribute for object definition

icon_image

This is the %s attribute for object definition

icon_image_alt

This is the %s attribute for object definition

initial_state

This is the %s attribute for object definition

is_volatile

This is the %s attribute for object definition

low_flap_threshold

This is the %s attribute for object definition

max_check_attempts

This is the %s attribute for object definition

merge_with_host()

Moves a service from its original file to the same file as the first effective host

notes

This is the %s attribute for object definition

notes_url

This is the %s attribute for object definition

notification_interval

This is the %s attribute for object definition

notification_options

This is the %s attribute for object definition

notification_period

This is the %s attribute for object definition

notifications_enabled

This is the %s attribute for object definition

object_type = 'service'
objects = <pynag.Model.ObjectFetcher object>
obsess_over_service

This is the %s attribute for object definition

passive_checks_enabled

This is the %s attribute for object definition

process_perf_data

This is the %s attribute for object definition

remove_from_contactgroup(contactgroup)
remove_from_servicegroup(servicegroup_name)

remove this service from a specific servicegroup

rename(shortname)

Not implemented. Do not use.

retain_nonstatus_information

This is the %s attribute for object definition

retain_status_information

This is the %s attribute for object definition

retry_interval

This is the %s attribute for object definition

service_description

This is the %s attribute for object definition

servicegroups

This is the %s attribute for object definition

stalking_options

This is the %s attribute for object definition

class pynag.Model.ServiceDependency(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

dependency_period

This is the %s attribute for object definition

dependent_host_name

This is the %s attribute for object definition

dependent_hostgroup_name

This is the %s attribute for object definition

dependent_service_description

This is the %s attribute for object definition

execution_failure_criteria

This is the %s attribute for object definition

host_name

This is the %s attribute for object definition

hostgroup_name

This is the %s attribute for object definition

inherits_parent

This is the %s attribute for object definition

notification_failure_criteria

This is the %s attribute for object definition

object_type = 'servicedependency'
objects = <pynag.Model.ObjectFetcher object>
service_description

This is the %s attribute for object definition

class pynag.Model.ServiceEscalation(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

contact_groups

This is the %s attribute for object definition

contacts

This is the %s attribute for object definition

escalation_options

This is the %s attribute for object definition

escalation_period

This is the %s attribute for object definition

first_notification

This is the %s attribute for object definition

host_name

This is the %s attribute for object definition

hostgroup_name

This is the %s attribute for object definition

last_notification

This is the %s attribute for object definition

notification_interval

This is the %s attribute for object definition

object_type = 'serviceescalation'
objects = <pynag.Model.ObjectFetcher object>
service_description

This is the %s attribute for object definition

class pynag.Model.Servicegroup(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

action_url

This is the %s attribute for object definition

add_service(shortname)

Adds service to this group. Behaves like _add_object_to_group(object, group)

alias

This is the %s attribute for object definition

downtime(start_time=None, end_time=None, trigger_id=0, duration=7200, author=None, comment='Downtime scheduled by pynag', recursive=False)

Put every host and service in this servicegroup in a schedule downtime.

Arguments:
start_time – When downtime should start. If None, use time.time() (now) end_time – When scheduled downtime should end. If None use start_time + duration duration – Alternative to end_time, downtime lasts for duration seconds. Default 7200 seconds. trigger_id – trigger_id>0 means that this downtime should trigger another downtime with trigger_id. author – name of the contact scheduling downtime. If None, use current system user comment – Comment that will be put in with the downtime recursive – For compatibility with other downtime commands, recursive is always assumed to be true
Returns:
None because commands sent to nagios have no return values
Raises:
ModelError if this does not look an active object.
get_effective_servicegroups()

Returns a list of every Servicegroup that is a member of this Servicegroup

get_effective_services()

Returns a list of all Service that belong to this Servicegroup

members

This is the %s attribute for object definition

notes

This is the %s attribute for object definition

notes_url

This is the %s attribute for object definition

object_type = 'servicegroup'
objects = <pynag.Model.ObjectFetcher object>
remove_service(shortname)

remove service from this group. Behaves like _remove_object_from_group(object, group)

servicegroup_members

This is the %s attribute for object definition

servicegroup_name

This is the %s attribute for object definition

class pynag.Model.Timeperiod(item=None, filename=None, **kwargs)

Bases: pynag.Model.ObjectDefinition

alias

This is the %s attribute for object definition

exclude

This is the %s attribute for object definition

object_type = 'timeperiod'
objects = <pynag.Model.ObjectFetcher object>
timeperiod_name

This is the %s attribute for object definition

pynag.Model.eventhandlers = []

eventhandlers – A list of Model.EventHandlers object.

all_attributes Module

macros Module

This file contains a dict object that maps Nagios Standard macronames to specific values.

i.e. macros[‘$HOSTADDR$’] should return ‘address’