Esempio n. 1
0
def main():
    import pprint
    implementation = detect_implementation()
    print('Running {}'.format(implementation))
    pprint.pprint(NTPProcess().getmetrics())
    checks = ['offset', 'peers', 'proc', 'reach', 'sync', 'vars']
    checkobjs = ntpchecks(checks, debug=True, implementation=implementation)
    from alert import NTPAlerter
    alerter = NTPAlerter(checks)
    alerter.alert(checkobjs, hostname=None, interval=0, format='telegraf')
Esempio n. 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 == '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)