diff --git a/nagixsc/__init__.py b/nagixsc/__init__.py
index 8f886ac5a9e46c8a75ddc2a2c449204199aabdc2..19ef4166cd963bfd5381b8a512144f299273a289 100644 (file)
--- a/nagixsc/__init__.py
+++ b/nagixsc/__init__.py
check['returncode'] = 127
return check
+ check['commandline'] = cmdline
+ check['command'] = cmdarray[0].split(os.path.sep)[-1]
+
if timeout:
signal.signal(signal.SIGALRM, exec_timeout_handler)
signal.alarm(timeout)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
timeout_returncode = 2
+ # Read "add_pnp4nagios_template_hint" from "[nagixsc]", default "False"
+ try:
+ add_pnp4nagios_template_hint = config.getboolean('nagixsc','add_pnp4nagios_template_hint')
+ except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
+ add_pnp4nagios_template_hint = False
+
# Sections are Hosts (not 'nagixsc'), options in sections are Services
hosts = config.sections()
if 'nagixsc' in hosts:
if '_host_check' in services and not opt_service:
cmdline = config.get(host, '_host_check')
check = exec_check(host_name, None, cmdline, timeout, timeout_returncode)
+ if add_pnp4nagios_template_hint and '|' in check['output']:
+ check['output'] += ' [%s]' % check['command']
checks.append(check)
cmdline = config.get(host, service)
check = exec_check(host_name, service, cmdline, timeout, timeout_returncode)
+ if add_pnp4nagios_template_hint and '|' in check['output']:
+ check['output'] += ' [%s]' % check['command']
checks.append(check)
return checks
timestamp = check['timestamp']
else:
timestamp = xmltimestamp
- count_services += 1
if check['service_description'] == None or check['service_description'] == '':
# Host check
- line = FORMAT_HOST % (now, check['host_name'], check['returncode'], check['output'].replace('\n', '\\n'))
+ line = FORMAT_HOST % (timestamp, check['host_name'], check['returncode'], check['output'].replace('\n', '\\n'))
else:
# Service check
- line = FORMAT_SERVICE % (now, check['host_name'], check['service_description'], check['returncode'], check['output'].replace('\n', '\\n'))
+ line = FORMAT_SERVICE % (timestamp, check['host_name'], check['service_description'], check['returncode'], check['output'].replace('\n', '\\n'))
if pipe:
pipe.write(line + '\n')
def write_xml(xmldoc, outfile, httpuser=None, httppasswd=None):
if outfile.startswith('http'):
(headers, body) = encode_multipart(xmldoc, httpuser, httppasswd)
-
- try:
- response = urllib2.urlopen(urllib2.Request(outfile, body, headers)).read()
- except urllib2.HTTPError, error:
- print error
- sys.exit(11)
- except urllib2.URLError, error:
- print error.reason[1]
- sys.exit(12)
-
- print response
+ response = urllib2.urlopen(urllib2.Request(outfile, body, headers)).read()
+ return response
elif outfile == '-':
xmldoc.saveFormatFile('-', format=1)
+ return None
else:
xmldoc.saveFile(outfile)
+ return None
+
+
+def write_xml_or_die(xmldoc, outfile, httpuser=None, httppasswd=None):
+ try:
+ response = write_xml(xmldoc, outfile, httpuser, httppasswd)
+ except urllib2.HTTPError, error:
+ print error
+ sys.exit(11)
+ except urllib2.URLError, error:
+ print error.reason[1]
+ sys.exit(12)
+
+ return response
##############################################################################