What is pynag?

py, as in python. nag, as in nagios

Latest 0.8.2

Install Instructions

OK, but what does it do?

Let's Parse some configs!

Parse the configuration, print information on hosts

from pynag import Model

# Get all hosts
all_hosts = Model.Host.objects.all
for i in all_hosts:
    print i.host_name, i.contact_groups 

We can also change Configs!

Find all services belonging to "examplehost" and change contactgroups

from pynag import Model

services = Model.Service.objects.filter(host_name='examplehost')
for i in services:
  i.contactgroups = "mycontactgroup"

Command Line Interface

List objects by hostname

$ pynag list object_type shortname where host_name="pynag.github.com"
object_type          shortname           
host                 pynag.github.com    
service              pynag.github.com/Ping
service              pynag.github.com/http://pynag.github.com
service              pynag.github.com/SSH Connectivity
----------5 objects matches search condition------------------------

Update hostname

$ pynag update host_name="www1" where host_name="www1.example.com"
object_type             shortname                                
host                    www1.example.com                        
service                 www1.example.com/Ping                  
service                 www1.example.com/http://www1.example.com
service                 www1.example.com/SSH Connectivity      
----------4 objects matches search condition----------------------
Update these 4 objects ? (y/N) 


28. Jun 2013 Released 0.5.0

pynag 0.5.0 is out!

Many enhancements and bugfixes, most notably towards unit testing, parsing performance and mk-livestatus tcp support

New Features:
  • pynag cli - new action "unset" to remove attributes when updating
  • PluginHelper - New option --pnp-compatible-perfdata
  • TCP Support for mk-livestatus
  • ObjectDefinitions now have new method: set_macro()
  • Vast improvements to unit testing
  • Fix unhandled tracebacks if invalid templates are defined
  • Utils.GitRepo has new method: show()
  • Vast performance improvement in parsing
  • ObjectDefinition now iterable
  • New Utility Class pynag.Utils.PluginOutput
  • ObjectDefinition: magic fields like shortname are now part of keys()
  • mk_livestatus new utility methods: get_servicegroups,hostgroups,etc
Noteworthy bug fixes:
  • travis-ci and coveralls.io support
  • Macroresolving when ARG1 contains other macros
  • get_suggested_filename() no longer returns filenames with invalid characters
  • check_range(): Always return True on invalid range_format
  • check_range(): raise exception on invalid input thresholds

30. Apr 2013 Released 0.4.9

The major changes in this release is mk-livestatus integration into the command line interface, the addition of a Parsers.LogFiles which gives API access to the Nagios logfiles:

$ pynag livestatus --get hosts --columns "name state last_state_change" --limit 10
name                     state                last_state_change   
Aftonian.example.com     0                    1364979198          
Ariminum.example.com     0                    1364979198          
Bashee.example.com       0                    1364979198          
Bernina.example.com      0                    1364978625          
Branchiopoda.example.com 0                    1364979198          
CRFMP.example.com        0                    1364978626          
Cassadaga.example.com    0                    1364979198          
Dieri.example.com        0                    1364979198          
Dorididae.example.com    0                    1364978627          
Drago.example.com        0                    1364979198          
----------10 objects matches search condition-----------------------------------
New Features:
  • pynag cli now has livestatus subcommand
  • pynag cli multiple changes to make it more friendly to bash scripts
  • pynag cli has acknowledge and downtime subcommands
  • pynag.Model.*.delete() now are more context aware and remove references from other objects
  • More features in pynag.Utils.GitRepo
  • Parser for retention.dat created
  • pynag.utils.grep_to_livestatus() to convert from pynag style filters to livestatus style filters
  • add_to_contactgroup() created for pynag.Model.Services, Hosts, and Contacts
  • New functions pynag.Utils.grep(). Model filter() will use this in the future
  • pynag.Model - object definitions now implement sort()
  • pynag.Parsers.Logfiles added to parse nagios log files
  • Multiple doctest and unittest fixes and improvements to code quality
  • send_nsca - revert back to tabs instead of spaces
  • Fix unhandled traceback with pynag copy
  • Fix bug where directories with ending .cfg were parsed as files
  • PluginHelper fixed in accordance to http://nagiosplugins.org/rfc/new_threshold_syntax

12. Dec 2012 Released 0.4.8

We are happy to announce release 0.4.8 version of pynag.

The major change in this release is the inclusion of mklivestatus interface which allows for faster access to nagios status information:

from pynag.Plugins import mk_livestatus
livestatus = mk_livestatus()
for service in livestatus.get_services():
    print service['host_name'], service['description'], service['state']
New Features:
  • MK Livestatus integration in pynag.Parsers.mk_livestatus
  • Testing framework for plugins in scripts/plugintest
  • Control.Command now uses livestatus if available.
  • pynag.Plugins.PluginHelper() prototype
  • Support for Nagios plugins new threshold format
  • New Service() objects with no host_name are not saved in None/service_description anymore.
  • GitEventHandler could not list files with spaces
  • pynag.Plugins.simple.check_range was very broken, fixed and added testing framework for pynag.Plugins
  • Fix for correctly returning exit codes in Control.daemon()
  • Static file parser now skips line not in format of key=value
  • pynag.Parsers.status.get_hoststatus() and pynag.Parsers.status.get_servicestatus() should raise a ValueError rather than return it.
  • timeperiod_name and alias were incorrectly saved
  • Unhandled exception in contact.get_effective_services()