Code Monkey home page Code Monkey logo

pynag's Introduction

Build Status Coverage Status PyPI version

About

Pynag, a tool and a library for managing Nagios/Naemon configuration and provides a framework to write plugins.

Pynag command-line utility offers the following features:

  • list python object definitions (e.g. list all hosts/services)
  • create new object definitions from command line
  • copy object definitions
  • remove object definitions
  • edit nagios.cfg from command-line

Pynag also has the following modules:

  • Model - Easy way to work with configuration as python objects
  • Plugins - convenience classes for writing python plugins
  • Parsers - Various parsers for Nagios configuration files
  • Control - Control of Nagios/Naemon daemon

Install

Using fedora/redhat:

yum install pynag

Using debian/ubuntu:

apt-get install python-pynag pynag

Using pip:

pip install pynag

Install latest git repository from source:

git clone https://github.com/pynag/pynag.git
cd pynag
python setup.py build
python setup.py install

Getting started

List all services:

import pynag.Model
all_services pynag.Model.Service.objects.all
for i in all_services:
	print i.host_name, i.service_description

Change an address of a host:

import pynag.Model
myhost = pynag.Model.Host.objects.get_by_shortname('myhost.example.com')
myhost.address = '127.0.0.1'
myhost.save()
# See what the host definition looks like after change:
print myhost

Create a new ssh service check for every host in the unix hostgroup:

import pynag.Model
hosts = pynag.Model.Host.objects.filter(hostgroup="unixservers")
for host in hosts:
    new_service = pynag.Model.Service()
    new_service.host_name = host.host_name
    new_service.service_description = "SSH Connectivity"
    new_service.check_command = "check_ssh"
    # optionally control where new object is saved:
    new_service.set_filename( host.get_filename() )
    new_service.save()

Further Documentation

We blatantly admit that documentation is scarce in pynag. Most of the documentation is in-line in pydoc strings in the respective python modules.

Any help with improving the documentation is much appreciated. For more documentation see

Pynag Command Line Tool

Pynag also comes with a command-line tool that gives good examples what is possible with the library. Some example commands:

list all hosts and their ip address:

pynag list host_name address where object_type=host

Change contactgroup for all services for a particular host:

pynag update set contactgroups=admins where host_name="myhost" and object_type=service

Copy a host, give it a new hostname and ip address:

pynag copy set host_name=newhost address=newaddress where object_type=host and host_name=oldhost
# Same for all its services:
pynag copy set host_name=newhost where object_type=service and host_name=oldhost

Known Issues

Model module's get_effective_* functions are not complete if your configuration is using regular expressions. For example, pynag.Model.Service.get_effective_hosts will fail on the following service definition:

define service {
    service_description check http
    check_command check_http
    host_name www*
}

Same applies for exemptions like this one:

define service {
    service_description check http
    check_command check_http
    hostgroup_name webservers
    host_name !dmzhost1,dmzhost2
}

Who uses pynag

There are a few open source projects out there that use pynag. The ones we know of are:

  • Adagios: Impressive web configuration and status interface
  • Okconfig: Monitoring pack generator for Nagios
  • RESTlos: generic RESTful api for nagios-like monitoring systems

Pynag is also used by lots of plugins around the world including:

  • check_eva.py
  • check_hpacucly.py
  • check_ipa/check_ipa_replication

Know of more projects using pynag ? Contact us and we'll add them here.

Contact us

If you need any help, want to contribute or just want to talk about pynag you can find us on one of the following:

pynag's People

Contributors

abhinav-upadhyay avatar andrewmcgilvray avatar awiddersheim avatar bne86 avatar crapworks avatar dekimsey avatar drewstinnett avatar eythori-sensa avatar gardart avatar gradecke avatar jeanfrancois42pin avatar llange avatar m1keil avatar mirrorz avatar mlvnd avatar netmarkjp avatar pall-valmundsson avatar palli avatar ppepos avatar puckch avatar refik avatar ryepup avatar stefanor avatar tomas-edwardsson avatar wasserman avatar zanglang avatar zothar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pynag's Issues

the 'execute' subcommand does not let one run checks linked to a host by hostgroups

When I try to execute a check for a host, the macros are not expanded appropriately. This results in the command not being executed correctly.

Some definitions for context:

define command {
        command_name    check_smtp
        command_line    /usr/lib/nagios/plugins/check_smtp -H '$HOSTADDRESS$'
}

define service {
        use                     generic-service
        service_description     SMTP
        check_command           check_smtp
        host_name         mail
}

# definition for host named 'mail' ...

When I try and execute this check, I get:

# pynag execute mail SMTP
# /usr/lib/nagios/plugins/check_smtp -H ''
check_smtp: Invalid hostname/address - 
Usage:
check_smtp -H host [-p port] [-e expect] [-C command] [-f from addr][-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout]
[-F fqdn] [-S] [-D days] [-v] [-4|-6]

# service check exited with exit code 3

so the macro $HOSTADDRESS$ is replaced with an empty string.

Unhandled exception in pynag.Parsers

Error occured, use --debug to see full traceback:

KeyError: 'contact'
Traceback (most recent call last):
File "/usr/bin/pynag", line 797, in
parse_arguments()
File "/usr/bin/pynag", line 80, in parse_arguments
list_objects()
File "/usr/bin/pynag", line 304, in list_objects
objects = search_objects(search_statements=where_statement)
File "/usr/bin/pynag", line 169, in search_objects
objects += pynag.Model.ObjectDefinition.objects.filter(**conditions)
File "/usr/lib/python2.6/site-packages/pynag/Model/init.py", line 463, in filter
for i in self.all:
File "/usr/lib/python2.6/site-packages/pynag/Model/init.py", line 324, in get_all
self.reload_cache()
File "/usr/lib/python2.6/site-packages/pynag/Model/init.py", line 345, in reload_cache
config.parse()
File "/usr/lib/python2.6/site-packages/pynag/Parsers/init.py", line 1147, in parse
self._post_parse()
File "/usr/lib/python2.6/site-packages/pynag/Parsers/init.py", line 868, in _post_parse
raw_item = self._apply_template( raw_item )
File "/usr/lib/python2.6/site-packages/pynag/Parsers/init.py", line 164, in _apply_template
parent_item = self._get_item( parent_name, object_type )
File "/usr/lib/python2.6/site-packages/pynag/Parsers/init.py", line 147, in _get_item
return self.item_cache[item_type].get(item_name, None)
KeyError: 'contact'

item_type = contact

item_name = 'generic-contact'

unhandled exception in Parsers.status.parse()

/usr/lib/python2.6/site-packages/pynag/Plugins/init.py:29: DeprecationWarning: The popen2 module is deprecated. Use the subprocess module.
from popen2 import Popen3
Traceback (most recent call last):
File "nagios-relay-config.py", line 62, in
main()
File "nagios-relay-config.py", line 38, in main
p.parse()
File "/usr/lib/python2.6/site-packages/pynag/Parsers/init.py", line 1316, in parse
if not self.data.has_key(status['meta']['type']):
KeyError: 'type'

pynag list misbehaving with __isnot

The following shows all objects (service/timeperiod/host...) where register is not 0

pynag list WHERE object_type=host AND register__isnot=0

Reversing the WHERE clause order makes the query function as expected

pynag list WHERE register__isnot=0 AND object_type=host

GitRepo.commit() does not return commit id

The method docs indicate that it returns the commit id. It doesn't, it just returns the output of the commit command. Should it?

Also related, _git_commit() vs. commit() and _git_add() vs. add(), which should be/is used?

Argument testing for plugins

Test for errors when supplying invalid options or incorrect usage of options, eg array on boolean, boolean with argument..

stack trace upon permission error

When I execute pynag as a normal user I get:

$ pynag list
Traceback (most recent call last):
  File "/usr/local/bin/pynag", line 523, in <module>
    parse_arguments()
  File "/usr/local/bin/pynag", line 59, in parse_arguments
    list_objects()
  File "/usr/local/bin/pynag", line 251, in list_objects
    objects = search_objects(search_statements=where_statement)
  File "/usr/local/bin/pynag", line 132, in search_objects
    objects += pynag.Model.ObjectDefinition.objects.filter(**conditions)
  File "/usr/local/lib/python2.6/dist-packages/pynag/Model/__init__.py", line 442, in filter
    for i in self.all:
  File "/usr/local/lib/python2.6/dist-packages/pynag/Model/__init__.py", line 305, in get_all
    self.reload_cache()
  File "/usr/local/lib/python2.6/dist-packages/pynag/Model/__init__.py", line 326, in reload_cache
    config.parse()
  File "/usr/local/lib/python2.6/dist-packages/pynag/Parsers/__init__.py", line 1083, in parse
    self.cfg_files = self.get_cfg_files()
  File "/usr/local/lib/python2.6/dist-packages/pynag/Parsers/__init__.py", line 1291, in get_cfg_files
    list = os.listdir(current_directory)
OSError: [Errno 13] Permission denied: '/etc/nagios3/conf.d'

that's on Debian Squeeze using pynag from source code (current master).

that error should be handled so that pynag only shows the error message and not the whole stack trace. e.g.:

# Parsers/__init__.py", line 1291
try:
  list = os.listdir(current_directory)
except os.OSError, e:
  fatal(e)  # whatever the call to echo an error to stderr and exit is in pynag..

pynag.Model.pynag_directory seems to have no effect

When I use the following config:
import pynag.Model

pynag.Model.cfg_file="/usr/local/icinga/etc/icinga.cfg"
pynag.Model.pynag_directory="/usr/local/icinga/etc/objects/pynag/"
... [add some new hosts etc..]

The new objects will appear under
/usr/local/icinga/etc/pynag instead of /usr/local/icinga/etc/objects/pynag/

Hence it seems like the pynag directory will always be /pynag

Traceback from parser

Environment:


Request Method: POST
Request URL: https://hortense.XXXXXXXXX.is/adagios/objectbrowser/advanced_edit/id=-5738657503752065611

Django Version: 1.3.1
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'adagios.objectbrowser',
 'adagios.rest',
 'adagios.misc',
 'adagios.okconfig_']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.6/site-packages/adagios/objectbrowser/views.py" in advanced_edit
  146.                 c['advanced_form'].save()
File "/usr/lib/python2.6/site-packages/adagios/objectbrowser/forms.py" in save
  259.         self.pynag_object.save()
File "/usr/lib/python2.6/site-packages/pynag/Model/__init__.py" in save
  684.                 save_result = config.item_edit_field(item=self._original_attributes, field_name=field_name, new_value=new_value)
File "/usr/lib/python2.6/site-packages/pynag/Parsers/__init__.py" in item_edit_field
  527.         return self._modify_object(item, field_name=field_name, new_value=new_value)
File "/usr/lib/python2.6/site-packages/pynag/Parsers/__init__.py" in _modify_object
  475.         buffer = "%s%s%s" % (''.join(everything_before), ''.join(object_definition), ''.join(everything_after))

Exception Type: UnicodeDecodeError at /objectbrowser/advanced_edit/id=-5738657503752065611
Exception Value: 'ascii' codec can't decode byte 0xc3 in position 135: ordinal not in range(128)

pynag copy

Should allow copy without a SET statement if a --filename is also specified.

It is useful if you are simply copying object (i.e. configuration migration) and you are confident that duplicates are ok.

unhandled exception with invalid syntax on "Pynag list"

pynag list a b where host_name=test and service_description=test test

Traceback (most recent call last):
File "/usr/bin/pynag", line 523, in ?
parse_arguments()
File "/usr/bin/pynag", line 59, in parse_arguments
list_objects()
File "/usr/bin/pynag", line 251, in list_objects
objects = search_objects(search_statements=where_statement)
File "/usr/bin/pynag", line 129, in search_objects
raise BaseException('Invalid statement: %s' %statement)
NameError: global name 'BaseException' is not defined

Timeperiod.set_attribute changes attribute name

I fetch my timeperiods with "timeperiods = Model.Timeperiod.objects.all" and I am using a for loop for iterating the timeperiods, just like in the examples. I want to change the value of the attribute "timeperiod_name":

I tried these two things:
timeperiod.set_attribute('timeperiod_name', 'foobar)
or:
timeperiod.timeperiod_name = 'foobar'

Before that I did the same for host, hostgroups, services, servicesgroups and it worked perfectly, there seems to be a problem with timeperiods because this is the result:

define timeperiod{
foobar 24x7

    alias           all except working hours

(... monday through friday and so one ...)
}

The attribute name is replaced by the value I want to set for timeperiod_name.

Traceback in parser if cfg_dir has a directory ending with .cfg

/usr/bin/python2.7 /home/palli/workspace/pynag/pynag/Utils/init.py
Traceback (most recent call last):
File "/home/palli/workspace/pynag/pynag/Utils/init.py", line 681, in
hosts = pynag.Model.Host.objects.all
File "/home/palli/workspace/pynag/pynag/Model/init.py", line 324, in get_all
self.reload_cache()
File "/home/palli/workspace/pynag/pynag/Model/init.py", line 345, in reload_cache
config.parse()
File "/home/palli/workspace/pynag/pynag/Parsers/init.py", line 1131, in parse
self._load_file(cfg_file)
File "/home/palli/workspace/pynag/pynag/Parsers/init.py", line 219, in _load_file
for line_num, line in enumerate( open(filename, 'rb').readlines() ):
IOError: [Errno 21] Is a directory: '/etc/nagios3/pynag/services/down01.example.com-host.cfg'

Process finished with exit code 1

broken CLI on current master

hello, just pulled from current master and reinstalled, and I now have the following stack trace when invoking "pynag" on the command line:

$ pynag
Traceback (most recent call last):
File "/usr/local/bin/pynag", line 26, in
import pynag.Model
File "/usr/local/lib/python2.6/dist-packages/pynag/Model/init.py", line 48, in
import pynag.Control.Command
ImportError: No module named Command

this submodule should be added to setup.py like that:

diff --git a/setup.py b/setup.py
index e757408..40bd4a2 100755
--- a/setup.py
+++ b/setup.py
@@ -38,6 +38,7 @@ if __name__ == "__main__":
             'pynag.Plugins',
             'pynag.Parsers',
             'pynag.Control',
+            'pynag.Control.Command',
             'pynag.Utils',
         ],
           data_files = [(manpath, [

Unhandled exception in resolve_sevicegroups

Traceback (most recent call last):
File "/usr/bin/pynag", line 797, in
parse_arguments()
File "/usr/bin/pynag", line 80, in parse_arguments
list_objects()
File "/usr/bin/pynag", line 304, in list_objects
objects = search_objects(search_statements=where_statement)
File "/usr/bin/pynag", line 169, in search_objects
objects += pynag.Model.ObjectDefinition.objects.filter(**conditions)
File "/usr/lib/python2.6/site-packages/pynag/Model/init.py", line 463, in filter
for i in self.all:
File "/usr/lib/python2.6/site-packages/pynag/Model/init.py", line 324, in get_all
self.reload_cache()
File "/usr/lib/python2.6/site-packages/pynag/Model/init.py", line 365, in reload_cache
ObjectRelations.resolve_servicegroups()
File "/usr/lib/python2.6/site-packages/pynag/Model/init.py", line 270, in resolve_servicegroups
ObjectRelations._resolve_servicegroup_members()
File "/usr/lib/python2.6/site-packages/pynag/Model/init.py", line 295, in _resolve_servicegroup_members
service = Service.objects.get_by_shortname(shortname)
File "/usr/lib/python2.6/site-packages/pynag/Model/init.py", line 402, in get_by_shortname
return ObjectFetcher._cached_shortnames[self.object_type][shortname]
KeyError: 'hostname/service'

Livestatus throws parser error

Minor issue, I was using a syntax that livestatus doesn't like spaces around equality (=) (made sense to me) and it throws out a pretty unhelpful messsage.

  • bad: host_name=<host>
  • good: host_name = <host>
[root@mon ~]# pynag livestatus --get hosts --filter "host_name=$(hostname --fqdn)"
Error occured, use --debug to see full traceback:

ParserError: "Header from livestatus socket does not start with 2: '400          78\n'"
[root@mon ~]# pynag livestatus --get hosts --filter "host_name = $(hostname --fqdn)"
name                
--------------------------------------------------------------------------------
mon.example.com
----------1 objects matches search condition------------------------------------

Services not related to service groups when defined as service group members

For example, when using the following configuration:

define service {
    host_name node-1
    service_description cpu
    check_command check_cpu
}

define servicegroup {
    servicegroup_name group-2
    alias Group 2
    members node-1,cpu
}

The following code will not return group-2:

service.get_effective_servicegroups()

I tried to add this feature myself by implementing _do_relations for the Servicegroup class, but the problem is that in this context I only have the host_name and service_description, which is not enough for populating the service_servicegroups and the servicegroup_services dictionaries.

Error Copying Host to New File, No Attribute get_filename

I am receiving an error when attempting to copy a host to a new host file. The copy is taking place but it seems like there's an error trying to call get_filename() when producing output.

Using the following command

pynag copy set host_name=localhost address=127.0.0.1 alias=localhost where object_type=host and host_name=oldhost --filename=/etc/nagios/objects/hosts/localhost.cfg --debug --verbose
Object saved to Error occured, use --debug to see full traceback:

AttributeError: 'list' object has no attribute 'get_filename'
Traceback (most recent call last):
  File "/usr/bin/pynag", line 589, in <module>
    parse_arguments()
  File "/usr/bin/pynag", line 70, in parse_arguments
    copy_object()
  File "/usr/bin/pynag", line 418, in copy_object
    print "Object saved to", new_obj.get_filename() 
AttributeError: 'list' object has no attribute 'get_filename'

The code that creates the error is here.

new_obj = obj.copy(filename=opts.filename,recursive=opts.recursive,**set)
print "Object saved to", new_obj.get_filename()

It seems that the code is trying to execute .get_filename() against the list itself rather than the objects inside the list which are objects that have the .get_filename attribute.

If I change new_obj.get_filename() to new_obj[0].get_filename() I get no error but the statement output only prints the list and not the full object.

Object saved to /etc/nagios/objects/hosts/localhost.cfg
# This is what actual statement looks like
[host: localhost]
1 objects copied.

Would we ever execute a copy and create multiple objects in the new_obj list? Couldn't we just assume there will only ever be one object?

Beginning of object definition not explicit enough

The beginning of object definition re may match non-object definitions. For example ;

define timeperiod {
        timeperiod_name         sample-blackout
        alias                           define outage time
        2011-02-21                  02:00-06:00
}

An effective fix for this is to require the regex to match known object types. ie ;

--- /home/gbyers/.local/lib/python2.6/site-packages/pynag/Parsers/__init__.py  2013-03-26 11:45:39.901462955 +1000
+++ pynag/Parsers/__init__.py   2013-03-26 11:34:27.799449007 +1000
@@ -239,7 +239,8 @@
                 continue

             # beginning of object definition
-            boo_re = re.compile("define\s+(\w+)\s*\{?(.*)$")
+            boo_re = re.compile("define\s+(%s)\s*\{?(.*)$" %
+                    '|'.join(self.object_type_keys.keys()))
             m = boo_re.search(line)
             if m:
                 tmp_buffer = [line]

New threshold syntax in perfdata output and pnp4nagios

Hey,
this is not a bug report but a suggestion for enhancement.

Currently a major graphing solution like pnp4nagios does not supports output in form of:
'label'=100;150..200;200..inf;;

From what I experienced, the graph won't be created/updated in case of such output.

I suggest adding a flag to PluginHelper that will turn on "legacy mode" that will allow to glue together new input style and old output style.
This way 150..200 in input will become @150:200 in output
and 200..inf in input will become ~:200 in output

Any thoughts?

Shortname None/None, fallback to 'name'

Shortname is None/None on the folllowing service, shouldn't it fallback if no service description is available to None/?

define service {
    name            cisco-switch1.example.com
    register        0
}

pynag.Model.get_effective_ reference invalid id after an object has been deleted

How to reproduce:

services = pynag.Model.Service.objects.filter(host_name="apc01.belgium.wolfram-hart.com", register=1)

service = services[0]
service.delete()
print "Service has been deleted", service.service_description
host = pynag.Model.Host.objects.get_by_shortname("apc01.belgium.wolfram-hart.com")
print "new host has been loaded"

print host.get_effective_services() # unhandled traceback

pynag CLI list WHERE documentation

Right now there isn't any good documentation on what to put in the WHERE clause for pynag cli

pynag list --help
Usage:  pynag list [attribute1] [attribute2] [WHERE <...>] 

Options:
  -h, --help     show this help message and exit
  --examples     Show example usage
  --print        Print actual definition instead of attributes
  --width=WIDTH  Column width in output (default 20)

PluginHelper Traceback on invalid threshold metrics

$ python check_http_multi/check_http_multi -u http://www.ok.is -u http://google.com/ --th metric=failed_percentage,0..20 
Traceback (most recent call last):
  File "check_http_multi/check_http_multi", line 89, in <module>
    main()
  File "check_http_multi/check_http_multi", line 62, in main
    plugin.check_all_metrics()
  File "/usr/lib/python2.7/site-packages/pynag/Plugins/__init__.py", line 815, in check_all_metrics
    parsed_threshold = new_threshold_syntax.parse_threshold(threshold)
  File "/usr/lib/python2.7/site-packages/pynag/Plugins/new_threshold_syntax.py", line 141, in parse_threshold
    raise PynagError("Invalid input: '%s' is not of the format key=value" % i)
pynag.Utils.PynagError: Invalid input: '0..20' is not of the format key=value

Model filter chaining support

Something on the lines of the following can be nice:

from pynag import Model

emea_north = Model.objects.filter(_geo='emea-north')
# Operational hours for emea north
for h in emea_north:
    h.notification_period = 'utc-8-18'

# Local Iceland guys take care of them selfs (fscking cowboys)
for h in emea_north.filter(_country='iceland'):
    h.contact_groups = 'is-admins'

# Guys in Sweden take care of rest of scandinavia
for h in emea_north.filter(_country_isnot='iceland'):
    h.contact_groups = 'se-admins'

pynag.Plugins new threshold is OK when returned value is not in OK range

Here is the original specification from http://nagiosplugins.org/rfc/new_threshold_syntax:

1 - If no levels are specified, return OK
2 - If an ok level is specified and value is within range, return OK
3 - If a critical level is specified and value is within range, return CRITICAL
4 - If a warning level is specified and value is within range, return WARNING
5 - If an ok level is specified, return CRITICAL
6 - Otherwise return OK

and here is the order in source:
1 - UNKNOWN int(3) -- On errors or bad input
2 - OK int(0) -- If value is within ok threshold
3 - CRITICAL int(2) -- if value is within critical threshold
4 - WARNING int(1) -- If value is within warning threshold
5 - OK int(0) -- If value is outside both warning and critical
6 - OK int(0) -- If no thresholds are provided

The problem is that by specification, I should get CRITICAL once my value is not in ok range, and no other range is specified. However, currently I'll get OK, probably because of step 5.

Example:

./check_buffer --th metric=sip,ok=10..20
| 'acct'=0;;;; 'auth'=0;;;; 'test'=None;;;; 'sip'=0;;;;
echo $?
0

0 is not in 10..20 and from specification I should have get CRITICAL (step 5).

pynag update

#2 issues,

pynag update throws this error on Red Hat Enterprise Linux Server release 6.2 (Santiago)

[root@manage puppet]# pynag  update 
/usr/lib/python2.6/site-packages/pynag/Plugins/__init__.py:29: DeprecationWarning: The popen2 module is deprecated.  Use the subprocess module.
  from popen2 import Popen3

pynag shows no help when running "pynag update"

pynag config --remove error

When trying to remove the localhost.cfg cfg_file an error is thrown.

[root@argus nagios]# pynag config --remove cfg_file=/etc/nagios/objects/localhost.cfg
Error occured, use --debug to see full traceback:

UnboundLocalError: local variable 'k' referenced before assignment

unhandled exception in pynag.Plugins

Traceback (most recent call last):
File "/usr/lib64/nagios/plugins/check_vtl", line 100, in
helper.exit()
File "/usr/lib/python2.6/site-packages/pynag/Plugins/init.py", line 733, in exit
plugin_output = self.get_plugin_output(exit_code=exit_code,summary=summary,long_output=long_output,perfdata=perfdata)
File "/usr/lib/python2.6/site-packages/pynag/Plugins/init.py", line 695, in get_plugin_output
return_buffer += "%s - " % state_text[exit_code]
KeyError: 127

Contactgroup.get_effective_contacts() unhandled exception

Unhandled exception when contactgroup.members is a comma seperated value and contains space.

i.e. run get_effective_contacts() on this contactgroup:

define contactgroup {
contactgroup_name example
members contact1, contact2
}

Parser.config exception contains perlvar - not interpolated

ParserError exception while parsing objects in pynag/Parsers/init.py still contains perl variable $line_no. Fix below.

--- pynag/Parsers/__init__.py   2012-09-14 02:37:13.000000000 +1000
+++ /home/gbyers/.local/lib/python2.6/site-packages/pynag/Parsers/__init__.py  2
013-03-26 11:53:37.401452487 +1000
@@ -248,7 +248,7 @@
                 current['meta']['line_start'] = line_num

                 if in_definition:
-                    raise ParserError("Error: Unexpected start of object definition in file '%s' on line $line_no.  Make sure you close preceding objects before starting a new one.\n" % filename)
+                    raise ParserError("Error: Unexpected start of object definition in file '%s' on line %d.  Make sure you close preceding objects before starting a new one.\n" % (filename, line_num))

                 ## Start off an object
                 in_definition = True

Better documentation for PluginHelper

The current documentation for PluginHelper doesn't seem to be complete. Like; is it the plugin authors responsibility to call parse_arguments()? How should you add extra arguments? Using the optionparser API can be a good option, but I'm not sure if that's the intended way or a method is just missing for it. A page similar to https://github.com/pynag/pynag/wiki/Plugin-Usage would go a long way.

pynag copy prints wrong destination filename

running pynag copy with --filename to control where a file is copied. It will say that it saved the object to a wrong filename:

pynag copy where name=mail-check_proc_sendmail --cfg_file=/tmp/nagios.cfg --filename=/tmp/migration.cfg SET __migrated=1

object_type shortname filename

service Process sendmail /etc/nagios/okconfig-old/templates/mail/services.cfg
----------1 objects matches search condition------------------------------------
Update these 1 objects ? (y/N) y
Object saved to /etc/nagios/okconfig-old/templates/mail/services.cfg

Deprecated use of popen2

[root@manage ~]# python
Python 2.6.6 (r266:84292, May  1 2012, 13:52:17) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pynag import Parsers
/usr/lib/python2.6/site-packages/pynag/Plugins/__init__.py:29: DeprecationWarning: The popen2 module is deprecated.  Use the subprocess module.
  from popen2 import Popen3
>>> 

discrepancy between list of objects when running 'list' and 'delete'

Using current master (from source) with Debian Squeeze

When I try and list objects with a certain where clause, I can see there are some definitions present:

$ sudo pynag list where host_name='monitoring1.lelutin.ca'
[sudo] password: 
object_type          shortname            filename            
--------------------------------------------------------------------------------
host                 monitoring1.lelutin.ca /etc/nagios3/conf.d/nagios_host.cfg
service              monitoring1.lelutin.ca/ssh_port_22 /etc/nagios3/conf.d/nagios_service.cfg
service              monitoring1.lelutin.ca/DISK /etc/nagios3/conf.d/nagios_service.cfg
service              monitoring1.lelutin.ca/SWAP /etc/nagios3/conf.d/nagios_service.cfg
----------4 objects matches search condition------------------------------------

But when I try and delete those, I'm told that pynag doesn't want to delete all objects, as if the search didn't return anything:

$ sudo pynag delete where host_name='monitoring1.lelutin.ca'
Usage: pynag delete <WHERE ...>

pynag: error: Refusing to update every object. Please trim down the selection with a WHERE statement

I've pretty-printed "where_clause" and "objects" inside the function "delete_objects()" of the main binary and I get this:

$ sudo pynag delete where host_name='monitoring1.lelutin.ca'
where_statement right after split_where_and_set() = ['host_name=monitoring1.lelutin.ca']
where_statement after search_objects() = []
objects = [host: monitoring1.lelutin.ca,
 service: monitoring1.lelutin.ca/ssh_port_22,
 service: monitoring1.lelutin.ca/DISK,
 service: monitoring1.lelutin.ca/SWAP]
Usage: pynag delete <WHERE ...>

pynag: error: Refusing to update every object. Please trim down the selection with a WHERE statement

so, apparently the function search_objects() is clearing out elements from where_statement. this needs to be fixed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.