Esempio n. 1
0
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"])
Esempio n. 2
0
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)
Esempio n. 3
0
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 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)
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
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 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,
        ),
    )
Esempio n. 9
0
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)
Esempio n. 10
0
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)
Esempio n. 11
0
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()
Esempio n. 12
0
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)
Esempio n. 13
0
def main():
    args = parse_cmdline(sys.argv[1:])
    Check(*Target(args)).main(verbose=args.verbosity > 0)
Esempio n. 14
0
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)