monitoringplugin.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. #####################################################################
  4. # (c) 2010-2011 by Sven Velt and team(ix) GmbH, Nuernberg, Germany #
  5. # sv@teamix.net #
  6. # #
  7. # This file is part of "team(ix) Monitoring Plugins" #
  8. # URL: http://oss.teamix.org/projects/monitoringplugins/ #
  9. # #
  10. # This file is free software: you can redistribute it and/or modify #
  11. # it under the terms of the GNU General Public License as published #
  12. # by the Free Software Foundation, either version 2 of the License, #
  13. # or (at your option) any later version. #
  14. # #
  15. # This file is distributed in the hope that it will be useful, but #
  16. # WITHOUT ANY WARRANTY; without even the implied warranty of #
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  18. # GNU General Public License for more details. #
  19. # #
  20. # You should have received a copy of the GNU General Public License #
  21. # along with this file. If not, see <http://www.gnu.org/licenses/>. #
  22. #####################################################################
  23. __version__ = '0.0.100802'
  24. __all__ = ['MonitoringPlugin', 'SNMPMonitoringPlugin']
  25. import optparse, os, re, sys
  26. try:
  27. import netsnmp
  28. except ImportError:
  29. pass
  30. class MonitoringPlugin(object):
  31. RETURNSTRINGS = { 0: "OK", 1: "WARNING", 2: "CRITICAL", 3: "UNKNOWN", 127: "UNKNOWN" }
  32. RETURNCODE = { 'OK': 0, 'WARNING': 1, 'CRITICAL': 2, 'UNKNOWN': 3 }
  33. returncode_priority = [2, 1, 3, 0]
  34. powers_binary = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']
  35. powers_binary_lower = [ p.lower() for p in powers_binary]
  36. powers_si = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z']
  37. powers_si_lower = [ p.lower() for p in powers_si]
  38. def __init__(self, *args, **kwargs):
  39. self.__pluginname = kwargs.get('pluginname') or ''
  40. self.__version = kwargs.get('version') or None
  41. self.__tagforstatusline = kwargs.get('tagforstatusline') or ''
  42. self.__tagforstatusline = self.__tagforstatusline.replace('|', ' ')
  43. self.__description = kwargs.get('description') or None
  44. self.__output = []
  45. self.__multilineoutput = []
  46. self.__performancedata = []
  47. self.__returncode = []
  48. self.__brain_checks = []
  49. self.__brain_perfdata = []
  50. self.__brain_perfdatalabels = []
  51. self.__optparser = optparse.OptionParser(version=self.__version, description=self.__description)
  52. self._cmdlineoptions_parsed = False
  53. def add_cmdlineoption(self, shortoption, longoption, dest, help, **kwargs):
  54. self.__optparser.add_option(shortoption, longoption, dest=dest, help=help, **kwargs)
  55. def parse_cmdlineoptions(self):
  56. if self._cmdlineoptions_parsed:
  57. return
  58. # self.__optparser.add_option('-V', '--version', action='version', help='show version number and exit')
  59. self.__optparser.add_option('-v', '--verbose', dest='verbose', help='Verbosity, more for more ;-)', action='count')
  60. (self.options, self.args) = self.__optparser.parse_args()
  61. self._cmdlineoptions_parsed = True
  62. def range_to_limits(self, range):
  63. # Check if we must negate result
  64. if len(range) > 0 and range[0] == '@':
  65. negate = True
  66. range = range[1:]
  67. else:
  68. negate = False
  69. # Look for a ':'...
  70. if range.find(':') >= 0:
  71. # ... this is a range
  72. (low, high) = range.split(':')
  73. if not low:
  74. low = float(0.0)
  75. elif low[0] == '~':
  76. low = float('-infinity')
  77. else:
  78. low = float(low)
  79. if high:
  80. high = float(high)
  81. else:
  82. high = float('infinity')
  83. elif len(range) == 0:
  84. low = float('-infinity')
  85. high = float('infinity')
  86. else:
  87. # ... this is just a number
  88. low = float(0.0)
  89. high = float(range)
  90. return (low, high, negate)
  91. def value_in_range(self, value, range):
  92. if range not in ['', None]:
  93. (low, high, negate) = self.range_to_limits(range)
  94. else:
  95. return True
  96. if value < low or value > high:
  97. result = False
  98. else:
  99. result = True
  100. if negate:
  101. result = not result
  102. return result
  103. def value_wc_to_returncode(self, value, range_warn, range_crit):
  104. if not self.value_in_range(value, range_crit):
  105. return 2
  106. elif not self.value_in_range(value, range_warn):
  107. return 1
  108. return 0
  109. def is_float(self, string):
  110. try:
  111. float(string)
  112. return True
  113. except ValueError:
  114. return False
  115. def special_value_wc_to_returncode(self, value, warn, crit):
  116. # Special add on: WARN > CRIT
  117. if self.is_float(warn) and self.is_float(crit) and float(warn) > float(crit):
  118. # Test if value is *smaller* than thresholds
  119. warn = '@0:' + warn
  120. crit = '@0:' + crit
  121. return self.value_wc_to_returncode(value, warn, crit)
  122. def add_output(self, value):
  123. self.__output.append(value)
  124. def add_multilineoutput(self, value):
  125. self.__multilineoutput.append(value)
  126. def format_performancedata(self, label, value, unit, *args, **kwargs):
  127. label = label.lstrip().rstrip()
  128. if re.search('[=\' ]', label):
  129. label = '\'' + label + '\''
  130. perfdata = label + '=' + str(value)
  131. if unit:
  132. perfdata += str(unit).lstrip().rstrip()
  133. for key in ['warn', 'crit', 'min', 'max']:
  134. perfdata += ';'
  135. if key in kwargs and kwargs[key]!=None:
  136. perfdata += str(kwargs[key])
  137. return perfdata
  138. def add_performancedata(self, perfdata):
  139. self.__performancedata.append(perfdata)
  140. def format_add_performancedata(self, label, value, unit, *args, **kwargs):
  141. self.add_performancedata(self.format_performancedata(label, value, unit, *args, **kwargs))
  142. def add_returncode(self, value):
  143. self.__returncode.append(value)
  144. def tagtarget(self, tag, target):
  145. if target:
  146. return str(tag) + ':' + str(target)
  147. else:
  148. return str(tag)
  149. def remember_check(self, tag, returncode, output, multilineoutput=None, perfdata=None, target=None):
  150. check = {}
  151. check['tag'] = tag
  152. check['returncode'] = returncode
  153. check['output'] = output
  154. check['multilineoutout'] = multilineoutput
  155. check['perfdata'] = perfdata
  156. check['target'] = target
  157. self.remember_perfdata(perfdata)
  158. self.__brain_checks.append(check)
  159. return check
  160. def remember_perfdata(self, perfdata=None):
  161. if perfdata:
  162. for pd in perfdata:
  163. if pd['label'] in self.__brain_perfdatalabels:
  164. pdidx = self.__brain_perfdatalabels.index(pd['label'])
  165. self.__brain_perfdata[pdidx] = pd
  166. else:
  167. self.__brain_perfdata.append(pd)
  168. self.__brain_perfdatalabels.append(pd['label'])
  169. def dump_brain(self):
  170. return (self.__brain_checks, self.__brain_perfdata)
  171. def brain2output(self):
  172. out = [[], [], [], []]
  173. for check in self.__brain_checks:
  174. tagtarget = self.tagtarget(check['tag'], check.get('target'))
  175. returncode = check.get('returncode') or 0
  176. self.add_returncode(returncode)
  177. out[returncode].append(tagtarget)
  178. #if returncode == 0:
  179. # self.add_output(tagtarget)
  180. #else:
  181. # self.add_output(tagtarget + '(' + check.get('output') + ') ')
  182. self.add_multilineoutput(self.RETURNSTRINGS[returncode] + ' ' + tagtarget + ' - ' + check.get('output'))
  183. if check.get('multilineoutput'):
  184. self.add_multilineoutput(check.get('multilineoutput'))
  185. statusline = []
  186. for retcode in self.returncode_priority:
  187. if len(out[retcode]):
  188. statusline.append(str(len(out[retcode])) + ' ' + self.RETURNSTRINGS[retcode] + ': ' + ' '.join(out[retcode]))
  189. statusline = ', '.join(statusline)
  190. self.add_output(statusline)
  191. for pd in self.__brain_perfdata:
  192. self.format_add_performancedata(**pd)
  193. def value_to_human_binary(self, value, unit=''):
  194. for power in self.powers_binary:
  195. if value < 1024.0:
  196. return "%3.1f%s%s" % (value, power, unit)
  197. value /= 1024.0
  198. if float(value) not in [float('inf'), float('-inf')]:
  199. return "%3.1fYi%s" % (value, unit)
  200. else:
  201. return value
  202. def value_to_human_si(self, value, unit=''):
  203. for power in self.powers_si:
  204. if value < 1000.0:
  205. return "%3.1f%s%s" % (value, power, unit)
  206. value /= 1000.0
  207. if float(value) not in [float('inf'), float('-inf')]:
  208. return "%3.1fY%s" % (value, unit)
  209. else:
  210. return value
  211. def human_to_number(self, value, total=None):
  212. if total:
  213. if not self.is_float(total):
  214. total = self.human_to_number(total)
  215. if self.is_float(value):
  216. return float(value)
  217. elif value[-1] == '%':
  218. if total:
  219. return float(value[:-1])/100.0 * float(total)
  220. else:
  221. if total in [0, 0.0]:
  222. return 0.0
  223. else:
  224. return float(value[:-1]) # FIXME: Good idea?
  225. elif value[-1].lower() in self.powers_si_lower:
  226. return 1000.0 ** self.powers_si_lower.index(value[-1].lower()) * float(value[:-1])
  227. elif value[-2:].lower() in self.powers_binary_lower:
  228. return 1024.0 ** self.powers_binary_lower.index(value[-2:].lower()) * float(value[:-2])
  229. else:
  230. return value
  231. def range_dehumanize(self, range, total=None):
  232. newrange = ''
  233. if len(range):
  234. if range[0] == '@':
  235. newrange += '@'
  236. range = range[1:]
  237. parts = range.split(':')
  238. newrange += ('%f' % self.human_to_number(parts[0], total)).rstrip('0').rstrip('.')
  239. if len(parts) > 1:
  240. newrange += ':' + ('%f' % self.human_to_number(parts[1], total)).rstrip('0').rstrip('.')
  241. if range != newrange:
  242. self.verbose(3, 'Changed range/thresold from "' + range + '" to "' + newrange + '"')
  243. return newrange
  244. else:
  245. return ''
  246. def verbose(self, level, output):
  247. if level <= self.options.verbose:
  248. print 'V' + str(level) + ': ' + output
  249. def max_returncode(self, returncodes):
  250. for rc in self.returncode_priority:
  251. if rc in returncodes:
  252. break
  253. return rc
  254. def exit(self):
  255. returncode = self.max_returncode(self.__returncode)
  256. self.back2nagios(returncode, statusline=self.__output, multiline=self.__multilineoutput, performancedata=self.__performancedata)
  257. def back2nagios(self, returncode, statusline=None, multiline=None, performancedata=None, subtag=None, exit=True):
  258. # FIXME: Make 'returncode' also accept strings
  259. # Build status line
  260. out = self.__tagforstatusline
  261. if subtag:
  262. out += '(' + subtag.replace('|', ' ') + ')'
  263. out += ' ' + self.RETURNSTRINGS[returncode]
  264. # Check if there's a status line text and build it
  265. if statusline:
  266. out += ' - '
  267. if type(statusline) == str:
  268. out += statusline
  269. elif type(statusline) in [list, tuple]:
  270. out += ', '.join(statusline).replace('|', ' ')
  271. # Check if we have multi line output and build it
  272. if multiline:
  273. if type(multiline) == str:
  274. out += '\n' + multiline.replace('|', ' ')
  275. elif type(multiline) in [list, tuple]:
  276. out += '\n' + '\n'.join(multiline).replace('|', ' ')
  277. # Check if there's perfdata
  278. if performancedata:
  279. out += '|'
  280. if type(performancedata) == str:
  281. out += performancedata
  282. elif type(performancedata) in [list, tuple]:
  283. out += ' '.join(performancedata).replace('|', ' ')
  284. # Exit program or return output line(s)
  285. if exit:
  286. print out
  287. sys.exit(returncode)
  288. else:
  289. return (returncode, out)
  290. ##############################################################################
  291. class SNMPMonitoringPlugin(MonitoringPlugin):
  292. def __init__(self, *args, **kwargs):
  293. # Same as "MonitoringPlugin.__init__(*args, **kwargs)" but a little bit more flexible
  294. #super(MonitoringPlugin, self).__init__(*args, **kwargs)
  295. MonitoringPlugin.__init__(self, *args, **kwargs)
  296. self.add_cmdlineoption('-H', '', 'host', 'Host to check', default='127.0.0.1')
  297. self.add_cmdlineoption('-P', '', 'snmpversion', 'SNMP protocol version', metavar='1', default='1')
  298. self.add_cmdlineoption('-C', '', 'snmpauth', 'SNMP v1/v2c community OR SNMP v3 quadruple', metavar='public', default='public')
  299. self.add_cmdlineoption('', '--snmpcmdlinepath', 'snmpcmdlinepath', 'Path to "snmpget" and "snmpwalk"', metavar='/usr/bin/', default='/usr/bin')
  300. # FIXME
  301. self.add_cmdlineoption('', '--nonetsnmp', 'nonetsnmp', 'Do not use NET-SNMP python bindings', action='store_true')
  302. # self.__optparser.add_option('', '--nonetsnmp', dest='nonetsnmp', help='Do not use NET-SNMP python bindings', action='store_true')
  303. self.__SNMP_Cache = {}
  304. self.__use_netsnmp = False
  305. self.__prepared_snmp = False
  306. def prepare_snmp(self):
  307. if not self._cmdlineoptions_parsed:
  308. self.parse_cmdlineoptions()
  309. if not self.options.nonetsnmp:
  310. try:
  311. import netsnmp
  312. self.__use_netsnmp = True
  313. except ImportError:
  314. pass
  315. if self.__use_netsnmp:
  316. self.verbose(1, 'Using NET-SNMP Python bindings')
  317. self.SNMPGET_wrapper = self.__SNMPGET_netsnmp
  318. self.SNMPWALK_wrapper = self.__SNMPWALK_netsnmp
  319. if self.options.snmpversion == '2c':
  320. self.options.snmpversion = '2'
  321. else:
  322. self.verbose(1, 'Using NET-SNMP command line tools')
  323. self.SNMPGET_wrapper = self.__SNMPGET_cmdline
  324. self.SNMPWALK_wrapper = self.__SNMPWALK_cmdline
  325. # Building command lines
  326. self.__CMDLINE_get = os.path.join(self.options.snmpcmdlinepath, 'snmpget') + ' -OqevtU '
  327. self.__CMDLINE_walk = os.path.join(self.options.snmpcmdlinepath, 'snmpwalk') + ' -OqevtU '
  328. if self.options.snmpversion in [1, 2, '1', '2', '2c']:
  329. if self.options.snmpversion in [2, '2']:
  330. self.options.snmpversion = '2c'
  331. self.__CMDLINE_get += ' -v' + str(self.options.snmpversion) + ' -c' + self.options.snmpauth + ' '
  332. self.__CMDLINE_walk += ' -v' + str(self.options.snmpversion) + ' -c' + self.options.snmpauth + ' '
  333. elif options.snmpversion == [3, '3']:
  334. # FIXME: Better error handling
  335. try:
  336. snmpauth = self.options.snmpauth.split(':')
  337. self.__CMDLINE_get += ' -v3 -l' + snmpauth[0] + ' -u' + snmpauth[1] + ' -a' + snmpauth[2] + ' -A' + snmpauth[3] + ' '
  338. self.__CMDLINE_walk += ' -v3 -l' + snmpauth[0] + ' -u' + snmpauth[1] + ' -a' + snmpauth[2] + ' -A' + snmpauth[3] + ' '
  339. except:
  340. self.back2nagios(3, 'Could not build SNMPv3 command line, need "SecLevel:SecName:AuthProtocol:AuthKey"')
  341. else:
  342. self.back2nagios(3, 'Unknown SNMP version "' + str(self.options.snmpversion) + '"')
  343. self.__CMDLINE_get += ' ' + self.options.host + ' %s 2>/dev/null'
  344. self.__CMDLINE_walk += ' ' + self.options.host + ' %s 2>/dev/null'
  345. self.verbose(3, 'Using commandline: ' + self.__CMDLINE_get)
  346. self.verbose(3, 'Using commandline: ' + self.__CMDLINE_walk)
  347. self.__prepared_snmp = True
  348. def find_index_for_value(self, list_indexes, list_values, wanted):
  349. self.verbose(2, 'Look for "' + str(wanted) + '"')
  350. index = None
  351. if len(list_indexes) != len(list_values):
  352. self.verbose(1, 'Length of index and value lists do not match!')
  353. return None
  354. try:
  355. index = list_values.index(wanted)
  356. index = list_indexes[index]
  357. except ValueError:
  358. pass
  359. if index:
  360. self.verbose(2, 'Found "' + str(wanted) +'" with index "' + str(index) + '"')
  361. else:
  362. self.verbose(2, 'Nothing found!')
  363. return index
  364. def find_in_table(self, oid_index, oid_values, wanted):
  365. self.verbose(2, 'Look for "' + str(wanted) + '" in "' + str(oid_values) +'"')
  366. index = None
  367. indexes = list(self.SNMPWALK(oid_index))
  368. values = list(self.SNMPWALK(oid_values))
  369. if len(indexes) != len(values):
  370. self.back2nagios(3, 'Different data from 2 SNMP Walks!')
  371. return self.find_index_for_value(indexes, values, wanted)
  372. def SNMPGET(self, baseoid, idx=None, exitonerror=True):
  373. if type(baseoid) in (list, tuple):
  374. if idx not in ['', None]:
  375. idx = '.' + str(idx)
  376. else:
  377. idx = ''
  378. if self.options.snmpversion in [1, '1']:
  379. value_low = long(self.SNMPGET_wrapper(baseoid[1] + idx, exitonerror=exitonerror))
  380. if value_low < 0L:
  381. value_low += 2 ** 32
  382. value_hi = long(self.SNMPGET_wrapper(baseoid[2] + idx, exitonerror=exitonerror))
  383. if value_hi < 0L:
  384. value_hi += 2 ** 32
  385. return value_hi * 2L ** 32L + value_low
  386. elif self.options.snmpversion in [2, 3, '2', '2c', '3']:
  387. return long(self.SNMPGET_wrapper(baseoid[0] + idx, exitonerror=exitonerror))
  388. elif type(baseoid) in (str, ) and idx != None:
  389. return self.SNMPGET_wrapper(baseoid + '.' + str(idx), exitonerror=exitonerror)
  390. else:
  391. return self.SNMPGET_wrapper(baseoid, exitonerror=exitonerror)
  392. def SNMPWALK(self, baseoid, exitonerror=True):
  393. return self.SNMPWALK_wrapper(baseoid, exitonerror=exitonerror)
  394. def __SNMPGET_netsnmp(self, oid, exitonerror=True):
  395. if not self.__prepared_snmp:
  396. self.prepare_snmp()
  397. if oid in self.__SNMP_Cache:
  398. self.verbose(2, "%40s -> (CACHED) %s" % (oid, self.__SNMP_Cache[oid]))
  399. return self.__SNMP_Cache[oid]
  400. result = netsnmp.snmpget(oid, Version=int(self.options.snmpversion), DestHost=self.options.host, Community=self.options.snmpauth)[0]
  401. if not result:
  402. if exitonerror:
  403. self.back2nagios(3, 'Timeout or no answer from "%s" looking for "%s"' % (self.options.host, oid))
  404. else:
  405. return None
  406. self.__SNMP_Cache[oid] = result
  407. self.verbose(2, "%40s -> %s" % (oid, result))
  408. return result
  409. def __SNMPWALK_netsnmp(self, oid, exitonerror=True):
  410. if not self.__prepared_snmp:
  411. self.prepare_snmp()
  412. if oid in self.__SNMP_Cache:
  413. self.verbose(2, "%40s -> (CACHED) %s" % (oid, self.__SNMP_Cache[oid]))
  414. return self.__SNMP_Cache[oid]
  415. result = netsnmp.snmpwalk(oid, Version=int(self.options.snmpversion), DestHost=self.options.host, Community=self.options.snmpauth)
  416. if not result:
  417. if exitonerror:
  418. self.back2nagios(3, 'Timeout or no answer from "%s" looking for "%s"' % (self.options.host, oid))
  419. else:
  420. return None
  421. self.__SNMP_Cache[oid] = result
  422. self.verbose(2, "%40s -> %s" % (oid, result))
  423. return result
  424. def __SNMPGET_cmdline(self, oid, exitonerror=True):
  425. if not self.__prepared_snmp:
  426. self.prepare_snmp()
  427. cmdline = self.__CMDLINE_get % oid
  428. self.verbose(2, cmdline)
  429. cmd = os.popen(cmdline)
  430. out = cmd.readline().rstrip().replace('"','')
  431. retcode = cmd.close()
  432. if retcode:
  433. if not exitonerror:
  434. return None
  435. if retcode == 256:
  436. self.back2nagios(3, 'Timeout - no SNMP answer from "' + self.options.host + '"')
  437. elif retcode ==512:
  438. self.back2nagios(3, 'OID "' + oid + '" not found')
  439. else:
  440. self.back2nagios(3, 'Unknown error code "' + str(retcode) + '" from command line utils')
  441. self.verbose(1, out)
  442. return out
  443. def __SNMPWALK_cmdline(self, oid, exitonerror=True):
  444. if not self.__prepared_snmp:
  445. self.prepare_snmp()
  446. cmdline = self.__CMDLINE_walk % oid
  447. self.verbose(2, cmdline)
  448. cmd = os.popen(cmdline)
  449. out = cmd.readlines()
  450. retcode = cmd.close()
  451. if retcode:
  452. if not exitonerror:
  453. return None
  454. if retcode == 256:
  455. self.back2nagios(3, 'Timeout - no SNMP answer from "' + self.options.host + '"')
  456. elif retcode ==512:
  457. self.back2nagios(3, 'OID "' + oid + '" not found')
  458. else:
  459. self.back2nagios(3, 'Unknown error code "' + str(retcode) + '" from command line utils')
  460. for line in range(0,len(out)):
  461. out[line] = out[line].rstrip().replace('"','')
  462. self.verbose(1, str(out))
  463. return out
  464. ##############################################################################
  465. def main():
  466. myplugin = MonitoringPlugin(pluginname='check_testplugin', tagforstatusline='TEST')
  467. from pprint import pprint
  468. pprint(myplugin.back2nagios(0, 'Nr. 01: Simple plugin', exit=False) )
  469. pprint(myplugin.back2nagios(0, 'Nr. 02: Simple plugin with sub tag', subtag='MySubTag', exit=False) )
  470. pprint(myplugin.back2nagios(0, 'Nr. 10: Exit Code OK', exit=False) )
  471. pprint(myplugin.back2nagios(1, 'Nr. 11: Exit Code WARNING', exit=False) )
  472. pprint(myplugin.back2nagios(2, 'Nr. 12: Exit Code CRITICAL', exit=False) )
  473. pprint(myplugin.back2nagios(3, 'Nr. 13: Exit Code UNKNOWN', exit=False) )
  474. ret = myplugin.back2nagios(0, 'Nr. 20: Plugin with string-based multiline output', 'Line 2\nLine 3\nLine4', exit=False)
  475. print ret[1]
  476. print 'Returncode: ' + str(ret[0])
  477. ret = myplugin.back2nagios(0, 'Nr. 21: Plugin with list-based multiline output', ['Line 2', 'Line 3', 'Line4'], exit=False)
  478. print ret[1]
  479. print 'Returncode: ' + str(ret[0])
  480. ret = myplugin.back2nagios(0, 'Nr. 22: Plugin with tuple-based multiline output', ('Line 2', 'Line 3', 'Line4'), exit=False)
  481. print ret[1]
  482. print 'Returncode: ' + str(ret[0])
  483. myplugin.add_performancedata('Val1', 42, '')
  484. myplugin.add_performancedata('Val2', 23, 'c', warn=10, crit=20, min=0, max=100)
  485. myplugin.add_performancedata('Val 3', '2342', 'c', warn=10, crit=20, min=0, max=100)
  486. pprint(myplugin.back2nagios(0, 'Nr. 30: With perfdatas', exit=False) )
  487. myplugin.back2nagios(0, 'Nr. 99: Exit test suite with OK')
  488. if __name__ == '__main__':
  489. main()
  490. #vim: ts=4 sw=4