Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sdk:scripts:ping-supervision [2015/05/05 15:04] (current)
Line 1: Line 1:
 +====== SDK Script ping-supervision.are ======
 +<code c ping-supervision.are>​
 +/* DESC: This script will supervise a specified host.
 + * Copyright (C) 2013 NetModule AG, Switzerland
 + */
 +
 +void usage()
 +{
 +    printf("​usage:​ ping-supervision.are <​host>​\n"​);​
 +    exit(1);
 +}
 +
 +if (argc < 2) {
 +    usage();
 +}
 +
 +HOST = argv[1];
 +INTERVAL = 5;
 +MAX_FAILURES = 3;
 +
 +failures = 0;
 +while (1) {
 +    ret = nb_ping(HOST);​
 +    if (ret != 1) {
 +        failures++;
 +        nb_syslog("​%s is not reachable (%d failures)",​ HOST, failures);
 +        if (failures >= MAX_FAILURES) {
 +            nb_syslog("​Initiating reboot after %d failures",​ failures);
 +            nb_reboot();​
 +            break;
 +        }
 +    } else {
 +        nb_syslog("​%s is up", HOST);
 +        failures = 0;
 +    }
 +    sleep(INTERVAL);​
 +}
 +
 +exit(0);
 +
 +</​code>​