def main(): # enable default alerting ok_status_exit_code = ceng_lib.ok_status_exit_code warning_status_exit_code = ceng_lib.warning_status_exit_code critical_status_exit_code = ceng_lib.critical_status_exit_code unknown_status_exit_code = ceng_lib.unknown_status_exit_code parser = argparse.ArgumentParser(description='Open a socket to port 80 and receives the service details.') parser.add_argument('server', help='the server you wish to connect to') parser.add_argument('--no-alert-on-warning', action='store_true', help='disable warning alerts and dashboard status\'s for this check (default: yes)') parser.add_argument("--no-alert-on-critical", action='store_true', help='disable critical alerts and dashboard status\'s for this check (default: yes)') parser.add_argument('--no-alert-on-unknown', action='store_true', help='disable unknown alerts and status\'s for this check (default: yes)') args = parser.parse_args() # check for a ctitical state, if so and warning is not set to no, then set critical to warning if args.no_alert_on_critical: critical_status_exit_code = 1 if args.no_alert_on_warning: critical_status_exit_code = 0 # check for a warning state, if so and critical is not set to no, then set warning to critical if args.no_alert_on_warning: warning_status_exit_code = 0 # if unknown is set to no, then set unknown to ok if args.no_alert_on_unknown: unknown_status_exit_code = 0 server = args.server # Execution start time start_time = datetime.now() # Open a socket to port 80 conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: conn.connect((server, 80)) except IOError: print('There is no service listening on port 80. Make sure the webserver is running and listening on port 80') sys.exit(critical_status_exit_code) else: pass # Check for the desired output output = ceng_lib.get_icinga_http_output(conn) conn.close() run_time = datetime.now() - start_time if output: print('%s; | \'Check_Time\'=%s;;;0.000000;60.000000;' % (output, run_time)) sys.exit(ok_status_exit_code) else: print('There is a problem with the https server; | \'Check_Time\'=%s;;;0.000000;60.000000;' % (run_time)) sys.exit(critical_status_exit_code)
def main(): ok_status_exit_code = ceng_lib.ok_status_exit_code warning_status_exit_code = ceng_lib.warning_status_exit_code critical_status_exit_code = ceng_lib.critical_status_exit_code unknown_status_exit_code = ceng_lib.unknown_status_exit_code parser = argparse.ArgumentParser(description='Ppens a socket to a remote port and receives a stream of data. Follow the examples in CEng_python_lib for examples on verifying output.') parser.add_argument('server', help='the hostname of the machine you wish to connect to') parser.add_argument('port', type=int, help='the port number you wish to connect to') parser.add_argument('url', help='the url you wish to check') parser.add_argument('--no-alert-on-warning', action='store_true', help='disable warning alerts and dashboard status\'s for this check (default: yes)') parser.add_argument("--no-alert-on-critical", action='store_true', help='disable critical alerts and dashboard status\'s for this check (default: yes)') parser.add_argument('--no-alert-on-unknown', action='store_true', help='disable unknown alerts and status\'s for this check (default: yes)') args = parser.parse_args() # check for a ctitical state, if so and warning is not set to no, then set critical to warning if args.no_alert_on_critical: critical_status_exit_code = 1 if args.no_alert_on_warning: critical_status_exit_code = 0 # check for a warning state, if so and critical is not set to no, then set warning to critical if args.no_alert_on_warning: warning_status_exit_code = 0 # if unknown is set to no, then set unknown to ok if args.no_alert_on_unknown: unknown_status_exit_code = 0 Port = args.port Server = args.server Url = args.url # Execution start time start_time = datetime.now() # Open a socket to port a port conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: conn.connect((Server, Port)) except IOError: print('There is no service listening on port 8080. Make sure the service is running and listening on port 8080') sys.exit(critical_status_exit_code) else: pass # Check for the desired output if Url == 'root': output = ceng_lib.get_port_output(conn) conn.close() run_time = datetime.now() - start_time elif Url == 'icinga-web': output = ceng_lib.get_icinga_http_output(conn) conn.close() run_time = datetime.now() - start_time if output: print('%s; | \'Check_Time\'=%s;;;0.000000;60.000000;' % (output, run_time)) sys.exit(ok_status_exit_code) else: print('There is a problem with the service on the server; | \'Check_Time\'=%s;;;0.000000;60.000000;' % (run_time)) sys.exit(critical_status_exit_code)
NRPE Examples ./check_nrpe -H hal2k1.foo.example.com -c icinga_check_memory.py -a 20 10 Local Example: ./icinga_check_memory.py 20 10 --critical no --warning yes TODO: ''' import sys from datetime import datetime import CEng_python_lib as ceng_lib import psutil import argparse # Get the hostname machine_name = ceng_lib.get_local_hostname() def main(): # enable default alerting ok_status_exit_code = ceng_lib.ok_status_exit_code warning_status_exit_code = ceng_lib.warning_status_exit_code critical_status_exit_code = ceng_lib.critical_status_exit_code unknown_status_exit_code = ceng_lib.unknown_status_exit_code parser = argparse.ArgumentParser(description='Retrieve the current Memory Utilization of a particular Host. Additional Performance Data is outputted along with Standard Status Information.') parser.add_argument('warning_threshold', type=int, help='the percentage of available memory left before entering a warning state') parser.add_argument('critical_threshold', type=int, help='the percentage of memory left before entering a critical state') parser.add_argument('--no-alert-on-warning', action='store_true', help='disable warning alerts and dashboard status\'s for this check (default: yes)') parser.add_argument("--no-alert-on-critical", action='store_true', help='disable critical alerts and dashboard status\'s for this check (default: yes)') parser.add_argument('--no-alert-on-unknown', action='store_true', help='disable unknown alerts and status\'s for this check (default: yes)')