{"id":65,"date":"2012-10-13T11:27:36","date_gmt":"2012-10-13T10:27:36","guid":{"rendered":"http:\/\/cyber-cottage.co.uk\/en\/?p=65"},"modified":"2012-10-13T11:27:36","modified_gmt":"2012-10-13T10:27:36","slug":"nagios-plugin-for-reading-the-asterisk-database","status":"publish","type":"post","link":"https:\/\/www.cyber-cottage.co.uk\/?p=65","title":{"rendered":"Nagios plugin for reading the Asterisk Database"},"content":{"rendered":"<p>This is a simple plugin that is based on one by\u00a0<a href=\"http:\/\/www.jasonrivers.co.uk\/\">Jason Rivers<\/a>\u00a0We have changed it now to read the ASTDB (Asterisk internal Database and then based on ok and Critical keys it will report OK or Critical staus reports to Nagios.<\/p>\n<p>This was written for reporting if an Elastix system is in Day or Night mode.<\/p>\n<p>You can define the Database Family, Key, Critical value and OK value. This means you can cutomise it to what ever you need to report.<\/p>\n<p>&nbsp;<\/p>\n<p>The Code is below, make you may need to change \/usr\/bin\/nc for what ever you use for netcat.<\/p>\n<p>any issues email us, but dont forget this is given for free not supported for free.<\/p>\n<pre>#!\/bin\/bash\n#\n# Program : check_asterisk_ami\n# :\n# Author : Original code by Jason Rivers &lt; jason@jasonrivers.co.uk &gt;\n# : Modified by Cyber-cottage.co.uk for checking the asterisk Database\n# :\n# Purpose : Nagios plugin to return Information from an Asterisk host using AMI\n# :\n# Parameters : --help\n# : --version\n# :\n# Returns : Standard Nagios status_* codes as defined in utils.sh\n# :\n# Licence : GPL\n#\n# Notes : See --help for details\n#============:==============================================================\nPROGNAME=`basename $0`\nPROGPATH=`echo $0 | \/bin\/sed -e 's,[\\\/][^\\\/][^\\\/]*$,,'`\nREVISION=`echo '$Revision: 1.1.0.6 $' | sed -e 's\/[^0-9.]\/\/g'`\n. $PROGPATH\/utils.sh\nprint_usage() {\necho \"Usage: $PROGNAME [-H hostname] [-u username] [-p password] [-P port] [-k DBkey] [-c critical] [-o ok] [-f family]\"\necho \" -H Hostname\"\necho \" -u AMI Username\"\necho \" -p AMI Password\"\necho \" -P (optional) AMI PORT\"\necho \" -k Database key\"\necho \" -f Database family\"\necho \" -c Critical Key\"\necho \" -o OK KEY\"\necho \"\"\necho \"SupportedCommands:\"\necho \" Most DB familiys that toggle such as DayNight in elastix\"\necho \"Usage: $PROGNAME --help\"\necho \"Usage: $PROGNAME --version\"\n}\nprint_help() {\nprint_revision $PROGNAME $REVISION\necho \"\"\necho \"Nagios Plugin to check Asterisk ASTDB using AMI\"\necho \"\"\nprint_usage\necho \"\"\necho \"Asterisk Call Status Check. orignal version by \u00a9 Jason Rivers 2011 changes to do ASTDB by cyber-cottage.co.uk\"\necho \"\"\nexit 0\n# support\n}\n# If we have arguments, process them.\n#\nexitstatus=$STATE_WARNING #default\nwhile test -n \"$1\"; do\ncase \"$1\" in\n--help)\nprint_help\nexit $STATE_OK\n;;\n-h)\nprint_help\nexit $STATE_OK\n;;\n--version)\nprint_revision $PROGNAME $REVISION\nexit $STATE_OK\n;;\n-V)\nprint_revision $PROGNAME $REVISION\nexit $STATE_OK\n;;\n-H)\nREMOTEHOST=$2;\nshift;\n;;\n-P) AMIPORT=$2;\nshift;\n;;\n-u) AMIUSER=$2;\nshift;\n;;\n-p) AMIPASS=$2;\nshift;\n;;\n-c)\nCRITICALNAME=$2\nshift;\n;;\n-o)\nOKNAME=$2\nshift;\n;;\n-k)\nDBKEY=$2;\nshift;\n;;\n-f)\nFAMIL=$2;\nshift;\n;;\n*)\necho \"Unknown argument: $1\"\nprint_usage\nexit $STATE_UNKNOWN\n;;\nesac\nshift\ndone\nif [ \"${AMIPORT}\" = \"\" ]; then\nAMIPORT=\"5038\"\nfi\nif [ \"${FAMIL}\" = \"\" ]; then\n##WARNING\necho=\"CRITICAL: Unknown KEY\"\nprint_help\nexit=$STATE_CRITICAL\nelse\n## Checking Astdb\nCHANNELS=`\/bin\/echo -e \"Action: login Username: ${AMIUSER} Secret: ${AMIPASS} Events: off Action: DBGet Family: ${FAMIL} Key: ${DBKEY} Action: Logoff \" | \/usr\/bin\/nc $REMOTEHOST ${AMIPORT} | awk '\/Val\/ {print $2}'|tr -d \" \"`\nif [ \"$CHANNELS\" = \"\" ]; then\necho \"UNKNOWN: Unable to get ASTDB status\"\nexit $STATUS_UNKNOWN\nfi\nif [ \"$CHANNELS\" = \"${OKNAME}\" ]; then\nexitstatus=$STATU_OK\nMSG=\"OK: ${DBKEY} Asterisk Emergency message not active\"\nelif [ \"$CHANNELS\" = \"\" ]; then\nexitstatus=$STATU_WARNING\nMSG=\"WARNING: Asterisk Unknown status\"\nelif [ \"$CHANNELS\" = \"$CRITICALNAME\" ]; then\nexitstatus=$STATU_CRITICAL\nMSG=\"CRITICAL: ${DBKEY} Asterisk Emergency message active\"\nfi\nfi\necho $MSG\nexit $exitstatus\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a simple plugin that is based on one by\u00a0Jason Rivers\u00a0We have changed it now to read the ASTDB (Asterisk internal Database and then based on ok and Critical keys it will report OK or Critical staus reports to Nagios. This was written for reporting if an Elastix system is in Day or Night [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11,7],"tags":[23,33,35,40,56,57,58,68,73,100,76,77],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-knowledge","category-technical","tag-asterisk","tag-digium","tag-elastix","tag-freepbx","tag-nagios","tag-network","tag-networking","tag-security","tag-support","tag-technical","tag-voip","tag-xorcom"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p5daZy-13","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65"}],"version-history":[{"count":0,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/65\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}