#!/usr/local/bin/python2.7 ##################################################################################################### # Name: check_opswise.py # # Created: 2015.06.24 # # Version: 1.0 # # Author: Rafiyath Shagir # # Purpose: This script checks status of all Opswise/UAG agents and alerts if any agent is # # "Offline". Based on Stonebranch's provided CLI program. Used with Nagios Core. # # # # PreReqs: 1. Python2.7 or above, but below python3.X. Python module argparse required. # # Tested on RHEL6. # # # # 2. Stonebranch's provided CLI program: ops-agent-status 5.2.0 Level 2 Release # # Build 141 02/16/15 08:31:07 xps 5.2.0 Level 4 Build 110 02/16/15 08:30:42 # # # # Installation: 1. Make sure you've met the PreReqs. Edit this script and set you python path. # # # # 2. Edit this script and set your Opswise environments to variable: # # parser.add_argument. Sample config provided for environments: # # dev, test, acc & prod. Add more if needed. Set your port, unless used # # default (7878). # # # # 3. Copy this script and the ops-agent-status program to your Nagios "libexec" dir, # # making sure appropriate permissions are set for your "nagios" user. # # # # 4. Test the script, I.e: # # [nagios@nagios_server libexec]$./check_opswise.py ops-agent-status prod # # OK: All UAG agents online. # # # # 5. If passed, configure Nagios. Example for configs in services.cfg and # # commands.cfg below. # # # # Sample config for services.cfg: # # # # OPSWISE OpsCli command check ops-agent-status: # # define service{ # # use generic-service # # name check_opswise_agent-status_prod # # host_name opswiseprod1,opswiseprod2 # # service_description PRODUCTION OPSWISE OpsCli command check ops-agent-status # # servicegroups prod_group # # check_command check_opswise_agent-status_prod! # # max_check_attempts 1 # # check_interval 5 # # check_period workhours_7-18 # # contact_groups admins # # notifications_enabled 1 # # notification_options u,c,r # # } # # # # Sample config for commands.cfg: # # # # define command{ # # command_name check_opswise_agent-status_prod # # command_line $USER1$/check_opswise.py ops-agent-status prod # # } # # # # # ##################################################################################################### import os,re,sys,subprocess,argparse parser = argparse.ArgumentParser(prog='check_opswise.py') parser.add_argument('throw', choices=['ops-agent-status']) parser.add_argument('env', choices=['dev', 'test', 'acc', 'prod']) #Edit your Opswise environments. args = parser.parse_args() chosen_option = format(args.throw) chosen_env = format(args.env) #Check for prog: ops-agent-status: if chosen_option == 'ops-agent-status' and chosen_env == 'dev': runScript = os.popen("./ops-agent-status -r OMS -m 7878@opswisedev -u ops.admin -p ops.admin.password") elif chosen_option == 'ops-agent-status' and chosen_env == 'test': runScript = os.popen("./ops-agent-status -r OMS -m 7878@opswisetest -u ops.admin -p ops.admin.password") elif chosen_option == 'ops-agent-status' and chosen_env == 'acc': runScript = os.popen("./ops-agent-status -r OMS -m 7878@opswiseacc -u ops.admin -p ops.admin.password") elif chosen_option == 'ops-agent-status' and chosen_env == 'prod': runScript = os.popen("./ops-agent-status -r OMS -m opswiseprod1:7878,opswiseprod2:7878 -u ops.admin -p ops.admin.password") result = runScript.read() if 'Offline' in result: print("ERROR: Found UAG agent(s) in Offline mode") print(result) sys.exit(2) elif 'Command Line authentication failed' in result: print("ERROR: Command Line authentication failed for user 'ops.admin'. Username and/or password invalid.") sys.exit(2) else: print("OK: All UAG agents online.") sys.exit(0)