Skip to content
This repository was archived by the owner on Nov 12, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions nagcgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class Nagcgi:
CMD_CUSTOM_COMMAND = 999
_time_fmt = '%m-%d-%Y %T'
debug = False
author = None

def __init__(self, hostname, userid = None, password = None,
secure = None, cgi = '/nagios/cgi-bin/cmd.cgi', debug = False):
Expand All @@ -198,22 +199,30 @@ def __init__(self, hostname, userid = None, password = None,
passwd=password)
auth_handler = urllib2.HTTPBasicAuthHandler(auth_manager)
self.opener = urllib2.build_opener(auth_handler)
self.opener.addheaders = [('User-agent', 'NagCGI Python Library/0.1')]
self.opener.addheaders = [
('User-agent', 'NagCGI Python Library/0.1'),
('Referer', self.uri)
]
return

def _dispatch(self, cmd, **kwargs):
'''Easily abused work-horse.

Send the completed command to the Nagios server. No checking.'''
if kwargs.has_key('author'):
if kwargs['author'] == None: kwargs['author'] = self.author
if not kwargs['author']: kwargs['author'] = self.author
kwargs['cmd_typ'] = cmd
kwargs['cmd_mod'] = self._commit
kwargs['btnSubmit'] = 'Commit'
if kwargs.has_key('host') and kwargs.has_key('service'):
kwargs['hostservice']=kwargs['host']+'^'+kwargs['service']
del kwargs['host']
del kwargs['service']
data = urllib.urlencode(kwargs)

if self.debug:
print "URI: %s" % (self.uri)
print "DATA: %s" % (data)
print("URI: %s" % (self.uri))
print("DATA: %s" % (data))

return self.opener.open(self.uri, data).read()

Expand Down