Пример #1
0
def main():
    args = parse_args()
    percentiles = args.percentiles.split(",")
    url_filters = {}
    exclude_patterns = []
    for expr in args.filter:
        label, urlprefix = expr.split(":", 1)
        url_filters[label] = urlprefix
    for pattern in args.exclude:
        exclude_patterns.append(pattern)
    check = nagiosplugin.Check(
        HAProxyLog(
            args.logfile,
            args.state_file,
            percentiles,
            url_filters,
            exclude_patterns,
        ),
        nagiosplugin.ScalarContext("http_errors", args.ew, args.ec),
        HAProxyLogSummary(percentiles),
    )
    for pct, i in zip(percentiles, itertools.count()):
        check.add(
            nagiosplugin.ScalarContext(
                "t_tot%s" % pct,
                args.tw[i],
                args.tc[i],
                "total req time (%s.pct) is {valueunit}" % pct,
            ))
    check.main(args.verbose, args.timeout)
def main():
    argp = argparse.ArgumentParser(description='Nagios plugin to check Nvidia GPU status using nvidia-smi')

    argp.add_argument('-w', '--gpu_warning', metavar='RANGE', default=0,
                      help='warning if threshold is outside RANGE')
    argp.add_argument('-c', '--gpu_critical', metavar='RANGE', default=0,
                      help='critical if threshold is outside RANGE')

    argp.add_argument('-W', '--mem_warning', metavar='RANGE', default=0,
                      help='warning if threshold is outside RANGE')
    argp.add_argument('-C', '--mem_critical', metavar='RANGE', default=0,
                      help='critical if threshold is outside RANGE')

    argp.add_argument('-t', '--gputemp_warning', metavar='RANGE', default=0,
                      help='warning if threshold is outside RANGE')
    argp.add_argument('-T', '--gputemp_critical', metavar='RANGE', default=0,
                      help='critical if threshold is outside RANGE')

    argp.add_argument('-d', '--device', default="0",
                      help='Device ID (starting from 0)')

    argp.add_argument('-v', '--verbose', action='count', default=0,
                      help='increase verbosity (use up to 3 times)')
    argp.add_argument('-m', '--memory', action='store_true',
                      help="Show memory used in % instead of utilization")
    args = argp.parse_args()

    check = nagiosplugin.Check(
        Utilization(args),
        nagiosplugin.ScalarContext('gpuutil', args.gpu_warning, args.gpu_critical),
        nagiosplugin.ScalarContext('memutil', args.mem_warning, args.mem_critical),
        nagiosplugin.ScalarContext('gpuTemp', args.gputemp_warning, args.gputemp_critical)
    )
    check.main(verbose=args.verbose)
Пример #3
0
def main():

    contexts = ['temperature', 'moisture', 'light', 'conductivity', 'battery']

    argp = argparse.ArgumentParser(description=__doc__)
    argp.add_argument('-m', '--mac', required=True, type=str,
                      help='Miflora MAC address')

    for context in contexts:
        argp.add_argument('--%s-warning' % context, metavar='RANGE', default='',
                      help='return warning if %s is outside RANGE' % context)
        argp.add_argument('--%s-critical' % context, metavar='RANGE', default='',
                      help='return critical if %s is outside RANGE' % context)

    argp.add_argument('-v', '--verbose', action='count', default=0,
                      help='increase output verbosity (use up to 3 times)')
    args = argp.parse_args()
    check = nagiosplugin.Check(
        Environment(args.mac),
        nagiosplugin.ScalarContext('temperature', args.temperature_warning, args.temperature_critical),
        nagiosplugin.ScalarContext('moisture', args.moisture_warning, args.moisture_critical),
        nagiosplugin.ScalarContext('light', args.light_warning, args.light_critical),
        nagiosplugin.ScalarContext('conductivity', args.conductivity_warning, args.conductivity_critical),
        nagiosplugin.ScalarContext('battery', args.battery_warning, args.battery_critical),
        EnvironmentSummary())
    check.main(verbose=args.verbose)
def main():
    argp = argparse.ArgumentParser()
    argp.add_argument(
        '-w',
        '--warning',
        metavar='RANGE',
        help='warning if backup age is outside RANGE in seconds'),
    argp.add_argument(
        '-c',
        '--critical',
        metavar='RANGE',
        help='critical if backup age is outside RANGE in seconds')
    argp.add_argument('-v',
                      '--verbose',
                      action='count',
                      default=0,
                      help='increase output verbosity (use up to 3 times)')
    argp.add_argument('-t',
                      '--timeout',
                      default=10,
                      help='abort execution after TIMEOUT seconds')
    argp.add_argument('--base-path',
                      default="/srv/backup/",
                      help="Path to the bank of the vault (/srv/backup)")
    argp.add_argument('--max-duration',
                      default=3600,
                      metavar='RANGE',
                      help="max time to take a backup in seconds (3600)")
    argp.add_argument('--branch',
                      default="default",
                      help="Branch to check (default)")
    argp.add_argument('vault', help='Name of the vault to check')
    args = argp.parse_args()
    check = nagiosplugin.Check(
        Backup(args.vault, args.base_path, args.branch),
        BoolContext(name='stale_lockfile',
                    critical=True,
                    fmt_metric=Bool_Fmt_Metric('LockFile is OK!',
                                               'LockFile is stale!')),
        BoolContext('valid_backup_found',
                    critical=False,
                    fmt_metric=Bool_Fmt_Metric('Valid backup found!',
                                               'No valid Backup found!')),
        nagiosplugin.ScalarContext(
            'last_success', args.warning, args.critical,
            Duration_Fmt_Metric('Last successful backup is {valueunit} old')),
        nagiosplugin.ScalarContext(
            'last_try', args.warning, args.critical,
            Duration_Fmt_Metric('Last backup tried {valueunit} ago')),
        nagiosplugin.ScalarContext(
            name='duration',
            warning=args.max_duration,
            fmt_metric=Duration_Fmt_Metric('Last backuprun took {valueunit}')),
        nagiosplugin.ScalarContext(name='running_backup_for',
                                   warning=args.max_duration,
                                   critical=args.max_duration * 3,
                                   fmt_metric=Duration_Fmt_Metric(
                                       'Running backup since {valueunit}')),
    )
    check.main(args.verbose, args.timeout)
Пример #5
0
def get_check(hours_warn, hours_crit, host=None, path=None, tags=None):
    return Check(
        ResticRepo(host=host, path=path, tags=tags),
        nagiosplugin.ScalarContext("snapshot",
                                   warning=hours_warn,
                                   critical=hours_crit),
        nagiosplugin.ScalarContext("size"),
        nagiosplugin.ScalarContext("files"))
Пример #6
0
def create_contexts(interfaces, defspeed, defduplex):
    yield nagiosplugin.ScalarContext("auto_spd", "", defspeed)
    yield DuplexContext("auto_dup", defduplex)
    for iface in interfaces:
        name, speed, duplex = (iface + ",,").split(",")[0:3]
        yield nagiosplugin.ScalarContext("{}_spd".format(name), "", speed
                                         or defspeed)
        yield DuplexContext("{}_dup".format(name), duplex or defduplex)
Пример #7
0
def main():
    html_auth = None
    args = parser()
    check = nagiosplugin.Check(
        Oozie(args),
        nagiosplugin.ScalarContext('errors', args.warning, args.critical),
        nagiosplugin.ScalarContext('coordinators', '1:', '1:'))
    check.main()
Пример #8
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)
Пример #9
0
def main():
    args = parse_args()
    percentiles = args.percentiles.split(',')
    check = nagiosplugin.Check(
        HAProxyLog(args.logfile, args.state_file, percentiles),
        nagiosplugin.ScalarContext('error_rate', args.ew, args.ec))
    for pct, i in zip(percentiles, itertools.count()):
        check.add(nagiosplugin.ScalarContext(
            'ttot%s' % pct, args.tw[i], args.tc[i],
            'total time (%s.pct) is {valueunit}' % pct))
    check.main(args.verbose, args.timeout)
Пример #10
0
def main():
    argp = SNMPSkeletton.default_args('Check memory on Cisco.')
    args = argp.parse_args()

    check = nagiosplugin.Check(
        CiscoMem(args.host, args.port, args.community, args.version),
        nagiosplugin.ScalarContext('alert_mem_percent',
                                   args.warning, args.critical),
        nagiosplugin.ScalarContext('mem_used'),
        nagiosplugin.ScalarContext('mem_total'))
    check.main()
Пример #11
0
def create_check(args):
    """
    Creates and configures a check for the sessioninfo command.

    :return: the sessioninfo check.
    """
    return np.Check(
        SessInfo(args.host, args.token),
        np.ScalarContext('session', args.warn, args.crit),
        np.ScalarContext('throughput'),
        SessSummary())
Пример #12
0
def main():
    argp = SNMPSkeletton.default_args('Check memory on Sun.')
    args = argp.parse_args()
    check = nagiosplugin.Check(
        SunMem(args.host, args.port, args.community, args.version),
        nagiosplugin.ScalarContext('alert_mem',
                                   args.warning,
                                   args.critical,
                                   fmt_metric='alert_mem is {value}%'),
        nagiosplugin.ScalarContext('graph_swap'))
    check.main()
Пример #13
0
def check_backup(Collector, config):
    return (
        Collector(
            config['config'],
            config['facility'],
        ),
        nagiosplugin.ScalarContext('age',
                                   config['warning'],
                                   config['warning']),
        nagiosplugin.ScalarContext('size', "1:", "1:"),
    )
Пример #14
0
def main():
    timeout = 10  # default
    args = parser()
    check = nagiosplugin.Check(
        ZookeeperZnode(args), stringContext.StringContext('true', True),
        stringContext.StringContext('false', False),
        nagiosplugin.ScalarContext('total_topics', args.warn_topics,
                                   args.crit_topics),
        nagiosplugin.ScalarContext('hosts', args.warn_hosts, args.crit_hosts))
    if args.test == "kafka":
        timeout = 0
    check.main(timeout=timeout)
Пример #15
0
def main():
    argp = SNMPSkeletton.default_args('Check storage on Windows file systems.')
    argp.add_argument('--filesystem', '-f',
                      help='ID Filesystem'),
    args = argp.parse_args()
    check = nagiosplugin.Check(
        WinStorage(args.host, args.port, args.community,
                   args.version, args.filesystem),
        nagiosplugin.ScalarContext('alert_fs_percent',
                                   args.warning, args.critical),
        nagiosplugin.ScalarContext('fs_used'),
        nagiosplugin.ScalarContext('fs_total'))
    check.main()
Пример #16
0
def main():
    args = parser()
    check = nagiosplugin.Check(
        Resourcemanager(args), stringContext.StringContext('state', 'STARTED'),
        stringContext.StringContext('nodeState', 'RUNNING'),
        nagiosplugin.ScalarContext('unhealthy', args.unhealthy_warn,
                                   args.unhealthy_crit),
        nagiosplugin.ScalarContext('lost', args.lost_warn, args.lost_crit),
        nagiosplugin.ScalarContext('rebooted', args.rebooted_warn,
                                   args.rebooted_crit),
        nagiosplugin.ScalarContext('appsPending', args.apps_warn,
                                   args.apps_crit))
    check.main()
Пример #17
0
def main():
    args = parser()
    check = nagiosplugin.Check(
        Flume(args),
        nagiosplugin.ScalarContext('io',
                                   args.batch_size,
                                   fmt_metric='{value} msg differs'),
        nagiosplugin.ScalarContext(
            'LastMsg',
            str(int(time.time()) * 1000 - args.timeout_war * 1000) + ':',
            str(int(time.time()) * 1000 - args.timeout_crit * 1000) + ':',
            fmt_metric='Last msg recived in {value}'))
    check.main()
Пример #18
0
def main():
    args = parse_args()
    check = nagiosplugin.Check(
        PureFAalert(args.endpoint, args.apitoken),
        nagiosplugin.ScalarContext(
            'critical', args.warning_crit, args.critical_crit,
            fmt_metric='{value} critical messages'),
        nagiosplugin.ScalarContext(
            'warning', args.warning_warn, args.critical_warn,
            fmt_metric='{value} warning messages'),
        nagiosplugin.ScalarContext(
            'info', args.warning_info, args.critical_info,
            fmt_metric='{value} info messages'))
    check.main(args.verbose, args.timeout)
def main():
    args = parser()
    check = nagiosplugin.Check(
        QJM(args),
        nagiosplugin.ScalarContext('processing', args.process_warn,
                                   args.process_crit),
        nagiosplugin.ScalarContext('sync', args.sync_threshold_warn,
                                   args.sync_threshold_crit),
        stringContext.StringContext('connection', "OK"),
        nagiosplugin.ScalarContext(
            'quorum',
            nagiosplugin.Range("%s:" % str(len(args.qjm.split(',')) / 2)),
            nagiosplugin.Range("%s:" % str(len(args.qjm.split(',')) / 2))))
    check.main()
Пример #20
0
def main():
    timeout = 10  # default
    args = parser()
    check = nagiosplugin.Check(
        StormTopology(args),
        stringContext.StringContext('connected',
                                    True,
                                    fmt_metric='Connection status: {value}'),
        nagiosplugin.ScalarContext('1d load', args.load_1d_warn,
                                   args.load_1d_crit),
        nagiosplugin.ScalarContext('3h load', args.load_3h_warn,
                                   args.load_3h_crit),
        nagiosplugin.ScalarContext('10m load', args.load_10m_warn,
                                   args.load_10m_crit))
    check.main(timeout=timeout)
Пример #21
0
def main():
    """
    :return:
    """
    argp = argparse.ArgumentParser(description='Nagios/Icinga check for Kubernetes Nodes')
    argp.add_argument('-v', '--version', action='version', version='%(prog)s ' + version)
    argp.add_argument('--kube-config', help='Kubernetes Config File')
    args = argp.parse_args()

    check = nagiosplugin.Check(
        Nodes(args.kube_config),
        nagiosplugin.ScalarContext('problem_nodes', 1, 2),
        nagiosplugin.ScalarContext('all_nodes')
    )
    check.main()
Пример #22
0
def main():
    argp = argparse.ArgumentParser(description=__doc__)
    argp.add_argument('-l',
                      '--logfile',
                      metavar='FILE',
                      default='/var/log/mail.log',
                      help='Postfix logfile (default: /var/log/mail.log)')
    argp.add_argument('-m',
                      '--mode',
                      metavar='MODE',
                      default='minute',
                      help='mode to check: minute, hour, day, week \
                      (default: minute)')
    argp.add_argument('-w',
                      '--warning',
                      metavar='RANGE',
                      default='',
                      help='return warning if value is outside RANGE')
    argp.add_argument('-c',
                      '--critical',
                      metavar='RANGE',
                      default='',
                      help='return critical if value is outside RANGE')
    args = argp.parse_args()

    check = nagiosplugin.Check(
        Postfix(logfile=args.logfile, mode=args.mode),
        nagiosplugin.ScalarContext(args.mode, args.warning, args.critical),
        LoadSummary(args.mode))
    check.main(timeout=120)
Пример #23
0
def main():
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('-v', '--verbose', action='count', default=0)
    arg_parser.add_argument('-H', '--host', required=True, nargs=1)
    arg_parser.add_argument('-p', '--portscan-range', nargs=1,
                            metavar='PORT_RANGE', help='port range, e.g.: 1-1024')
    arg_parser.add_argument('-a', '--allowed-ports', nargs=1, default='',
                            metavar='PORTS', help='list of ports split by "," (comma)')
    arg_parser.add_argument('-n', '--nmap-extra-args', nargs=1)
    args = arg_parser.parse_args()
    checker = OpenPortsResource('PORT SECURITY SCANNER')
    checker.target_host = args.host[0]
    if args.portscan_range:
        checker.portscan_range = args.portscan_range[0]
    else:
        checker.portscan_range = '1-65535'
    if args.allowed_ports and len(args.allowed_ports) > 0:
        checker.allowed_ports = args.allowed_ports[0].split(',')
    if args.nmap_extra_args:
        checker.nmap_extra_args = args.nmap_extra_args[0]
    check = nagiosplugin.Check(
        checker,
        OpenPortsContext('ports'),
        nagiosplugin.ScalarContext('unknown_ports_count', critical='0:0'),
    )
    check.main(args.verbose, timeout=0)
Пример #24
0
def main():
    args = parse_args()
    check = nagiosplugin.Check(
        Rubrikrunway(args.rubrik_ip, args.rubrik_user, args.rubrik_pass))
    check.add(
        nagiosplugin.ScalarContext('rk_runway', args.warning, args.critical))
    check.main(args.verbose, args.timeout)
def main():

    args = parse_args()
    check = nagiosplugin.Check(
        CohesityAlerts(args))
    check.add(
        nagiosplugin.ScalarContext(
            'critical',
            critical='~:0'
        ))
    check.add(
        nagiosplugin.ScalarContext(
            'warning',
            warning='~:0'
        ))
    check.main(args.verbose, args.timeout)
Пример #26
0
def half_installed_check(config):
    return (HalfRemoved(),
            nagiosplugin.ScalarContext(
                'halfinstalled',
                config['warning'],
                config['warning'],
                fmt_metric='{value} half-installed packages'))
Пример #27
0
def main():
    args = get_argparser().parse_args()

    objects = []

    if args.unit:
        objects.append(SystemctlIsActiveResource(unit=args.unit))
    else:
        objects += [
            SystemdctlListUnitsResource(excludes=args.exclude),
            PerformanceDataContext(),
            SystemdAnalyseResource(),
        ]

    objects += [
        UnitContext(),
        nagiosplugin.ScalarContext(
            name='startup_time',
            warning=args.warning,
            critical=args.critical,
        ),
        SystemdSummary()
    ]

    check = nagiosplugin.Check(*objects)
    check.main(args.verbose)
Пример #28
0
def main():
    argp = SNMPSkeletton.default_args('Check temperature on Dell.')
    args = argp.parse_args()
    check = nagiosplugin.Check(
        DellTemp(args.host, args.port, args.community, args.version),
        nagiosplugin.ScalarContext('alert_temp', args.warning, args.critical))
    check.main()
Пример #29
0
def main():
    argp = argparse.ArgumentParser(description=__doc__)
    argp.add_argument('-w',
                      '--warning',
                      metavar='RANGE',
                      default='',
                      help='return warning if activeVisitors is outside RANGE')
    argp.add_argument(
        '-c',
        '--critical',
        metavar='RANGE',
        default='',
        help='return critical if activeVisitors is outside RANGE')
    argp.add_argument('-D', '--data', action='store', required=True)
    argp.add_argument('-V', '--view', action='store', required=True)
    argp.add_argument('-v',
                      '--verbose',
                      action='count',
                      default=0,
                      help='increase output verbosity (use up to 3 times)')

    args = argp.parse_args()
    check = nagiosplugin.Check(
        RealtimeVisitors(args.data, args.view),
        nagiosplugin.ScalarContext('activeVisitors', args.warning,
                                   args.critical))
    check.main(verbose=args.verbose)
Пример #30
0
def main():
    """
    :return:
    """
    argp = argparse.ArgumentParser(
        description='Nagios/Icinga check for Kubernetes Pods')
    argp.add_argument('-v',
                      '--version',
                      action='version',
                      version='%(prog)s ' + version)
    argp.add_argument('--kube-config', help='Kubernetes Config File')

    for phase in Pods.phases:
        argp.add_argument('--warning-' + phase.lower())
        argp.add_argument('--critical-' + phase.lower())

    args = argp.parse_args()

    checks = [Pods(args.kube_config)]
    for phase in Pods.phases:
        checks.append(
            nagiosplugin.ScalarContext(
                phase, getattr(args, 'warning_' + phase.lower()),
                getattr(args, 'critical_' + phase.lower())))

    checks.append(PodsSummary())

    check = nagiosplugin.Check(*checks)
    check.main()