示例#1
0
def main():
    validchecks = ['proc', 'offset', 'peers', 'reach', 'reachability', 'sync', 'trace', 'vars']
    defaultchecks = ['proc', 'offset', 'peers', 'reach', 'sync', 'vars']
    args = get_args(validchecks)
    if args.check is None or len(args.check) < 1:
        args.check = defaultchecks
    else:
        # turn 'reachability' into 'reach' for backwards compatibility
        for i in range(0, len(args.check)):
            if args.check[i] == 'reachability':
                args.check[i] = 'reach'

    if args.test:
        # read from standard input in test mode
        checkobjs = {
            'peers': NTPPeers([x.rstrip() for x in sys.stdin.readlines()]),
        }
    else:
        # run the checks
        checkobjs = ntpchecks(args.check, debug=args.debug)

    # alert on what we've collected
    alerter = NTPAlerter(args.check)
    alerter.alert_nagios(checkobjs=checkobjs, debug=args.debug)
    sys.exit(alerter.return_code())
示例#2
0
def main():
    checks = ['proc', 'offset', 'peers', 'reach', 'sync', 'vars', 'trace']
    args = get_args()

    if 'COLLECTD_HOSTNAME' in os.environ:
        args.mode = 'collectd'
        hostname = os.environ['COLLECTD_HOSTNAME']
    else:
        hostname = socket.getfqdn()

    if 'COLLECTD_INTERVAL' in os.environ:
        args.mode = 'collectd'
        if args.interval is None:
            args.interval = float(os.environ['COLLECTD_INTERVAL'])

    if args.interval is None:
        args.interval = 60

    if args.mode != 'collectd':
        warnings.warn('Only collectd mode is currently supported')
        sys.exit(1)

    while True:
        # run the checks
        checkobjs = ntpchecks(checks, debug=False)

        # alert on what we've collected
        alerter = NTPAlerter(checks, checkobjs)
        alerter.alert_collectd(hostname, args.interval)
        sleep_until(args.interval)
示例#3
0
def main():
    checks = ['proc', 'offset', 'peers', 'reach', 'sync', 'vars', 'trace']
    args = get_args()

    if 'COLLECTD_HOSTNAME' in os.environ:
        args.mode = 'collectd'
        hostname = os.environ['COLLECTD_HOSTNAME']
    else:
        hostname = socket.getfqdn()

    if 'COLLECTD_INTERVAL' in os.environ:
        args.mode = 'collectd'
        if args.interval is None:
            args.interval = float(os.environ['COLLECTD_INTERVAL'])

    if args.interval is None:
        args.interval = 60

    if args.mode != 'collectd':
        warnings.warn('Only collectd mode is currently supported')
        sys.exit(1)

    while True:
        # run the checks
        checkobjs = ntpchecks(checks, debug=False)

        # alert on what we've collected
        alerter = NTPAlerter(checks, checkobjs)
        alerter.alert_collectd(hostname, args.interval)
        sleep_until(args.interval)
示例#4
0
def main():
    validchecks = ['proc', 'offset', 'peers', 'reach', 'sync', 'trace', 'vars']
    defaultchecks = ['proc', 'offset', 'peers', 'reach', 'sync', 'vars']
    args = get_args(validchecks)
    if args.check is None or len(args.check) < 1:
        args.check = defaultchecks

    if args.test:
        # read in ntpq output in test mode
        checkobjs = {
            'peers': NTPPeers([x.rstrip() for x in sys.stdin.readlines()]),
        }
    else:
        # run the checks
        checkobjs = ntpchecks(args.check, args.debug)

    # alert on what we've collected
    alerter = NTPAlerter(args.check, checkobjs)
    alerter.alert_nagios(args.debug)
    sys.exit(alerter.return_code())
示例#5
0
文件: ntpmon.py 项目: paulgear/ntpmon
def main():
    checks = ['proc', 'offset', 'peers', 'reach', 'sync', 'vars']
    args = get_args()

    if 'COLLECTD_HOSTNAME' in os.environ:
        args.mode = 'collectd'
        hostname = os.environ['COLLECTD_HOSTNAME']
    else:
        hostname = socket.getfqdn()

    if 'COLLECTD_INTERVAL' in os.environ:
        args.mode = 'collectd'
        if args.interval is None:
            args.interval = float(os.environ['COLLECTD_INTERVAL'])

    if args.interval is None:
        args.interval = 60

    if args.mode == 'telegraf' and not sys.stdout.isatty():
        (host, port) = args.connect.split(':')
        port = int(port)
        s = socket.socket()
        s.connect((host, port))
        sys.stdout = s.makefile(mode='w')

    alerter = alert.NTPAlerter(checks)
    implementation = None
    while True:
        # cache implementation for the lifetime of ntpmon
        if not implementation:
            implementation = process.detect_implementation()

        if implementation:
            # run the checks
            checkobjs = process.ntpchecks(checks, debug=False, implementation=implementation)
            # alert on what we've collected
            alerter.alert(checkobjs=checkobjs, hostname=hostname, interval=args.interval, format=args.mode)

        sleep_until(args.interval)
示例#6
0
def main():
    checks = ['proc', 'offset', 'peers', 'reach', 'sync', 'vars', 'trace']
    args = get_args()

    if 'COLLECTD_HOSTNAME' in os.environ:
        args.mode = 'collectd'
        hostname = os.environ['COLLECTD_HOSTNAME']
    else:
        hostname = socket.getfqdn()

    if 'COLLECTD_INTERVAL' in os.environ:
        args.mode = 'collectd'
        if args.interval is None:
            args.interval = float(os.environ['COLLECTD_INTERVAL'])

    if args.interval is None:
        args.interval = 60

    if args.mode == 'telegraf':
        (host, port) = args.connect.split(':')
        port = int(port)
        s = socket.socket()
        s.connect((host, port))
        sys.stdout = s.makefile(mode='w')

    alerter = NTPAlerter(checks)
    while True:
        # run the checks
        checkobjs = ntpchecks(checks, debug=False)

        # alert on what we've collected
        alerter.alert(checkobjs=checkobjs,
                      hostname=hostname,
                      interval=args.interval,
                      format=args.mode)
        sleep_until(args.interval)