pynag <sub-command> [options] [arguments]
pynag is a command-line utility that can be used to view or change current nagios configuration.
print to screen nagios configuration objects as specified by a WHERE clausepynag list [attribute1] [attribute2] [WHERE ...]
modify specific attributes of nagios objects as specified by a WHERE and SET clausepynag update set attr1=value WHERE attr=value and attr=value
Delete objects from nagios configuration as specified by a WHERE clausepynag delete delete <WHERE ...>
Add a new object definitionpynag add <object_type> <attr1=value1> [attr2=value2]
Copy objects, specifiying which attributes to changepynag copy <WHERE ...> <SET attr1=value1 [attr2=value2] ...>
Executes the currently configured check command for a host or a servicepynag execute <host_name> [service_description]
modify values in main nagios configuration file (nagios.cfg)pynag config [–set <attribute=value>] [–old_value=attribute]pynag config [–append <attribute=value>] [–old_value=attribute]pynag config [–remove <attribute>] [–old_value=attribute]pynag config [–get <attribute>]
Some Subcommands use WHERE statements to filter which objects to work with. Where has certain similarity with SQL syntax.
- WHERE <attr=value> [AND attr=value] [OR attr=value][another where statement]
where “attr” is any nagios attribute (i.e. host_name or service_description).
- pynag list WHERE host_name=localhost and object_type=servicepynag list WHERE object_type=host or object_type=service
Any search attributes have the same syntax as the pynag filter. For example these work just fine:
pynag list WHERE host_name__contains=productionpynag list WHERE host_name__startswith=prodpynag list WHERE host_name__notcontains=testpynag list host_name address WHERE address__exists=Truepynag list host_name WHERE register__isnot=0
The pynag filter supports few parameters that are not just attributes.
- filename – The filename which the object belongs
- id – pynag unique identifier for the object
- effective_command_line – command which nagios will execute
Of course these can be combined with the pynag filter syntax:
pynag list where filename__startswith=/etc/nagios/conf.d/pynag list host_name service_description effective_command_line
For detailed description of the filter see pydoc for pynag.Model.ObjectDefintion.filter()
Subcommands that use SET statements (like update or copy) use them a list of attributes change for a specific object.
- SET <attr1=value1> [attr2=value2] [...]
- pynag update SET address=127.0.0.1 WHERE host_name=localhost and object_type=host