/* 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 = 10; 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);