def check(processors, **args): """ Invoke the InfluxDB check using the Nagios plugin framework. Reads the query from the processors chain. """ query = processors[0]() client = InfluxDBClient( host=args["hostname"], port=args["port"], username=args["username"], password=args["password"], database=args["database"], timeout=args["timeout"], ) check = Check( Measurements( query=query, client=client, ), ScalarContext(COUNT, args["count_warning_range"], args["count_error_range"]), ScalarContext(MEAN, args["mean_warning_range"], args["mean_error_range"]), MeasurementValuesSummary(query=query, )) check.main(args["verbose"])
def main(): # Base function which is calling main Monitoring functions args = RequestManager.default_args('Check CPU') # Initiating default args # Adding some extra args needed for this method args.add_argument('--sys', '-s', required=True, type=str, help='System Name') pargs = args.parse_args() # Parsing given args resources = [] # Creating Context Params array to pass to Nagiosplugin check function for res in PERFDATA['data'].keys(): if not res.find('alert') == -1: resources.append(ScalarContext(res, pargs.warning, pargs.critical)) else: resources.append(ScalarContext(res)) # Calling Nagiosplugin Check function to get translated monitoring data check = Check( CheckCPU(pargs.host, pargs.port, pargs.community, pargs.version, pargs.sys), *resources) check.main(pargs.verbose)
def main(): # Base function which is calling main Monitoring functions args = RequestManager.default_args('Check Linux Memory') # Initiating default args pargs = args.parse_args() # Parsing given args resources = [] # Creating Context Params array to pass to Nagiosplugin check function for pd in PERFDATA: if pd.return_value: CONTEXT = ScalarContext if pd.context: CONTEXT = pd.context if not pd.key.find('alert') == -1: resources.append(CONTEXT(pd.key, pargs.warning, pargs.critical)) else: resources.append(CONTEXT(pd.key)) # Calling Nagiosplugin Check function to get translated monitoring data check = Check( CheckMemory(pargs.host, pargs.port, pargs.community, pargs.version, perfdata=PERFDATA, indexes=INDEXES), *resources, ) check.main(pargs.verbose)
def main(): # Base function which is calling main Monitoring functions args = RequestManager.default_args('Check Interface Traffic') # Initiating default args # Adding some extra args needed for this method args.add_argument('--descr', '-d',type=str, required=True, help='Interface description') args.add_argument('--bandwidth', '-b', type=float, help='Interface bandwidth') pargs = args.parse_args() # Parsing given args resources = [] # Creating Context Params array to pass to Nagiosplugin check function for key, val in multiple_perfdata[ARCH]['PERFDATA']['data'].items(): if not 'meta' in val: CONTEXT = ScalarContext if 'context' in val: CONTEXT = val['context'] if not key.find('alert') == -1: resources.append(CONTEXT(key, pargs.warning, pargs.critical)) else: resources.append(CONTEXT(key)) # Calling Nagiosplugin Check function to get translated monitoring data check = Check( InterfaceTraffic(pargs.host, pargs.port, pargs.community, pargs.version, interface=pargs.descr, bandw=pargs.bandwidth), *resources, ) check.main(pargs.verbose)
def main(): parser = argparse.ArgumentParser( description='Check nginx upstreams via nginx_upstream_check_module' ) parser.add_argument('-u', '--url', required=True, help='url to check (output must be json-formatted)') parser.add_argument('-c', '--critical', default=49, help='Critical threshold for number ' 'of DOWN upstreams (in percent)') parser.add_argument('-w', '--warning', default=25, help='Warning threshold for number ' 'of DOWN upstreams (in percent)') parser.add_argument('-v', '--verbose', action='count', default=0, help='increase output verbosity (use up to 3 times)') args = parser.parse_args() status = json.loads(urlopen(args.url).read()) upstreams = set(server['upstream'] for server in status['servers']['server']) contexts = (ScalarContext( upstream, critical=args.critical, warning=args.warning, fmt_metric='{value} % servers are down in {name} upstream' ) for upstream in upstreams) check = Check(NginxUpstreams(status, upstreams), *contexts) check.main(args.verbose, timeout=60)
def check(processors, **args): """ Invoke the InfluxDB check using the Nagios plugin framework. Reads the query from the processors chain. """ query = processors[0]() client = InfluxDBClient( host=args["hostname"], port=args["port"], username=args["username"], password=args["password"], database=args["database"], timeout=args["timeout"], ) check = Check( Measurements( query=query, client=client, ), ScalarContext(COUNT, args["count_warning_range"], args["count_error_range"]), ScalarContext(MEAN, args["mean_warning_range"], args["mean_error_range"]), MeasurementValuesSummary( query=query, ) ) check.main(args["verbose"])
def main(): # Base function which is calling main Monitoring functions args = RequestManager.default_args('Check Memory') # Initiating default args pargs = args.parse_args() # Parsing given args resources = [] # Creating Context Params array to pass to Nagiosplugin check function for key, val in PERFDATA['data'].items(): if not 'meta' in val: CONTEXT = ScalarContext if 'context' in val: CONTEXT = val['context'] if not key.find('alert') == -1: resources.append(CONTEXT(key, pargs.warning, pargs.critical)) else: resources.append(CONTEXT(key)) # Calling Nagiosplugin Check function to get translated monitoring data check = Check( CheckMemory(pargs.host, pargs.port, pargs.community, pargs.version), *resources, ) check.main(pargs.verbose)
def main(): a = argparse.ArgumentParser() a.add_argument('-c', '--critical', metavar='RANGE', default='500:', help='return critical if file is outside RANGE') args = a.parse_args() check = Check(JournalFile(), SimpleContext('critical', critical=args.critical), JournalFileSummary()) check.main()
def main(): argp = argparse.ArgumentParser(description=__doc__) argp.add_argument('-H', '--host', required=True, metavar='hostname', help='server hostname') argp.add_argument('-p', '--port', required=False, metavar='port', default=1489, type=int, help='server port, default 1489') argp.add_argument('-s', '--secure', action='store_true', help='use ssl') argp.add_argument('-f', '--fullmap', action='store_true', help='check for malicious servers registered on docbroker, ' '-d/--docbase argument must specify all servers supposed to be registered') argp.add_argument('-d', '--docbase', required=False, metavar='docbase', help='docbase name') argp.add_argument('-n', '--name', metavar='name', default='', help='name of check that appears in output') argp.add_argument('-t', '--timeout', metavar='timeout', default=60, type=int, help='check timeout, default is 60 seconds') argp.add_argument('-w', '--warning', metavar='RANGE', help='warning threshold') argp.add_argument('-c', '--critical', metavar='RANGE', help='critical threshold') args = argp.parse_args() if ':' in args.host: chunks = args.host.split(':') setattr(args, 'host', chunks[0]) setattr(args, 'port', int(chunks[1])) check = Check(CheckSummary()) if getattr(args, 'name', None): check.name = args.name check.add(CheckDocbroker(args, check.results)) check.add( ScalarContext( TIME_THRESHOLDS, getattr(args, "warning"), getattr(args, "critical"), fmt_metric=fmt_metric ) ) check.main(timeout=args.timeout)
def main(): args = parse_args() check = Check( CloudFileStats( args.username, args.api_key, args.container, float(args.timeout))) check.add(ScalarContext('time', args.warn, args.critical)) check.add(ScalarContext('count', '', '')) check.main(timeout=args.timeout)
def main(): # Base function which is calling main Monitoring functions args = RequestManager.default_args( 'Check Windows CPU') # Initiating default args pargs = args.parse_args() # Parsing given args resources = [] # Creating Context Params array to pass to Nagiosplugin check function for res in PERFDATA['data'].keys(): if not res.find('alert') == -1: resources.append(ScalarContext(res, pargs.warning, pargs.critical)) else: resources.append(ScalarContext(res)) # Calling Nagiosplugin Check function to get translated monitoring data check = Check( WindowsCPU(pargs.host, pargs.port, pargs.community, pargs.version), *resources) check.main(pargs.verbose)
def main(): args = parse_args() check = Check( Measurements( hostname=args.hostname, measurement=args.measurement, age=args.age, influxdb_hostname=args.influxdb_hostname, influxdb_port=args.influxdb_port, influxdb_username=args.influxdb_username, influxdb_password=args.influxdb_password, influxdb_database=args.influxdb_database, ), ScalarContext(COUNT, args.count_warning_range, args.count_error_range), ScalarContext(MEAN, args.mean_warning_range, args.mean_error_range), MeasurementValuesSummary( measurement=args.measurement, ) ) check.main(args.verbose)
def make_check(host, port, token, pattern, node, check_id): return Check( ConsulCheck( node=node, check_id=check_id, host=host, port=port, token=token, ), PassThroughContext( pattern=pattern, ), )
def main(): # Base function which is calling main Monitoring functions args = RequestManager.default_args( description='Check Linux Load') # Initiating default args # Adding some extra args needed for this method pargs = args.parse_args() # Parsing given args req_manager = SystemLoad(host=pargs.host, port=pargs.port, community=pargs.community, version=pargs.version) resources = [] # Creating Context Params array to pass to Nagiosplugin check function for res in PERFDATA['data'].keys(): if not res.find('alert') == -1: resources.append(ScalarContext(res, pargs.warning, pargs.critical)) else: resources.append(ScalarContext(res)) # Calling Nagiosplugin Check function to get translated monitoring data check = Check(req_manager, *resources) check.main()
def main(): # Base function which is calling main Monitoring functions args = RequestManager.default_args( 'Check Disk I/O') # Initiating default args # Adding some extra args needed for this method args.add_argument('--disk', '-d', required=True, type=str, help='Disk name') args.add_argument('--sleep-time', '-s', required=False, type=float, help="Sleep time", default=10.0) pargs = args.parse_args() # Parsing given args resources = [] # Creating Context Params array to pass to Nagiosplugin check function for res in PERFDATA['data'].keys(): if not res.find('alert') == -1: resources.append(ScalarContext(res, pargs.warning, pargs.critical)) else: resources.append(ScalarContext(res)) # Calling Nagiosplugin Check function to get translated monitoring data check = Check( DiskIO(pargs.host, pargs.port, pargs.community, pargs.version, disk=pargs.disk, sleep=getattr(pargs, 'sleep-time', 10)), *resources) check.main(pargs.verbose)
def main(): parser = argparse.ArgumentParser() parser.add_argument("hostname", help="the hostname", type=str) parser.add_argument("username", help="the snmp user name", type=str) parser.add_argument("authkey", help="the auth key", type=str) parser.add_argument("privkey", help="the priv key", type=str) parser.add_argument("mode", help="the mode", type=str, choices=["load", "memory", "disk", "storage", "update", "status"]) parser.add_argument("-w", help="warning value for selected mode", type=int) parser.add_argument("-c", help="critical value for selected mode", type=int) parser.add_argument('-v', '--verbose', action='count', default=0) args = parser.parse_args() warning = args.w critical = args.c check = None if args.mode == 'load': check = Check( Load(args.hostname, args.username, args.authkey, args.privkey), nagiosplugin.ScalarContext('load', warning, critical), LoadSummary()) elif args.mode == 'memory': check = Check( Memory(args.hostname, args.username, args.authkey, args.privkey), nagiosplugin.ScalarContext('memory', warning, critical), MemorySummary()) elif args.mode == 'disk': check = Check( Disk(args.hostname, args.username, args.authkey, args.privkey), nagiosplugin.ScalarContext('temp', warning, critical), DiskContext('disk_status'), DiskSummary()) elif args.mode == 'storage': check = Check( Storage(args.hostname, args.username, args.authkey, args.privkey), nagiosplugin.ScalarContext('storage', warning, critical), StorageSummary()) elif args.mode == 'update': check = Check( Update(args.hostname, args.username, args.authkey, args.privkey), UpdateContext('update'), UpdateSummary()) elif args.mode == 'status': check = Check( Status(args.hostname, args.username, args.authkey, args.privkey), nagiosplugin.ScalarContext('temp', warning, critical), StatusContext('status'), StatusSummary()) else: raise CheckError('Unknown mode', args.mode) check.main(args.verbose)
def main(): argp = argparse.ArgumentParser(description=__doc__) argp.add_argument('-H', '--host', required=True, metavar='hostname', help='server hostname') argp.add_argument('-p', '--port', required=False, metavar='port', type=int, help='server port') argp.add_argument('-i', '--docbaseid', required=False, metavar='docbaseid', type=int, help='docbase identifier') argp.add_argument('-l', '--login', metavar='username', help='username') argp.add_argument('-a', '--authentication', metavar='password', help='password') argp.add_argument('-s', '--secure', action='store_true', help='use ssl') argp.add_argument( '-t', '--timeout', metavar='timeout', default=60, type=int, help='check timeout, default is 60 seconds') argp.add_argument( '-m', '--mode', required=True, metavar='mode', help="mode to use, one of: " + ", ".join("%s (%s)" % (x, modes[x][3]) for x in modes.keys())) argp.add_argument('-j', '--jobs', metavar='jobs', default='', help='jobs to check, comma-separated list') argp.add_argument('-n', '--name', metavar='name', default='', help='name of check that appears in output') argp.add_argument('-q', '--query', metavar='query', default='', help='query to run') argp.add_argument('--stores', metavar='stores', default='', help='stores to check') argp.add_argument('-f', '--format', metavar='format', default='', help='query output format') argp.add_argument( '-w', '--warning', metavar='RANGE', help='warning threshold for query results, supported in following modes: ' + ", ".join(x for x in modes.keys() if modes[x][1])) argp.add_argument( '-c', '--critical', metavar='RANGE', help='critical threshold for query results, supported in following modes: ' + ", ".join(x for x in modes.keys() if modes[x][1])) argp.add_argument( '--warningtime', metavar='RANGE', help='warning threshold for execution time, supported in following modes: ' + ", ".join(x for x in modes.keys() if modes[x][2])) argp.add_argument( '--criticaltime', metavar='RANGE', help='critical threshold for execution time, supported in following modes: ' + ", ".join(x for x in modes.keys() if modes[x][2])) args = argp.parse_args() m = re.match('^(dctm(s)?://((.*?)(:(.*))?@)?)?([^/:]+?)(:(\d+))?(/(\d+))?$', args.host) if m: if m.group(2): setattr(args, 'secure', True) pass if m.group(4): setattr(args, 'login', m.group(4)) if m.group(6): setattr(args, 'authentication', m.group(6)) if m.group(7): setattr(args, 'host', m.group(7)) if m.group(9) is not None: setattr(args, 'port', int(m.group(9))) if m.group(11) is not None: setattr(args, 'docbaseid', int(m.group(11))) if args.login and not args.authentication: m = re.match('^(.*?):(.*)$', args.login) if m: setattr(args, 'login', m.group(1)) setattr(args, 'authentication', m.group(2)) check = Check(CheckSummary()) if args.name: check.name = args.name else: check.name = args.mode check.add(CheckDocbase(args, check.results)) check.add( ScalarContext( THRESHOLDS, getattr(args, "warning"), getattr(args, "critical"), fmt_metric=fmt_metric ) ) check.add( ScalarContext( TIME_THRESHOLDS, getattr(args, "warningtime"), getattr(args, "criticaltime"), fmt_metric=fmt_nometric, ) ) check.main(timeout=args.timeout)
def main(): # pragma: no cover args = parse_args() check = Check(CheckLayer2Link(args.ip, args.maxwait, args.count), ScalarContext('arp', None, '1:1'), AuditSummary()) check.main(args.verbose)
def main(): args = parse_cmdline(sys.argv[1:]) Check(*Target(args)).main(verbose=args.verbosity > 0)