I've been trying to install this pluggin on my nagios but i'm not able to make it works. I'm monitoring an asterisk server from my Nagios server and now i want to add this pluggin to monitorize a trunk SIP state. My goal is to set up an alert for this to be informed in case the SIP trunk is down. We have better deal with this provider so in case that the SIP trunk is down we can adjust our calling policy til the SIP trunk recovers and start using it again.
I think i finally install the pluggin but is not working as expected. I'm gonna write down all the process that i followed and if you can take a look and tell me where i'm wrong and how to fix it i'll grateful.
- First of all I add the pluggin .sh into my nagios pluggin folder.
- Then I went to commands.cfg and add the following command.
Code: Select all
define command{
command_name check_peer_status
command_line /usr/lib64/nagios/plugins/check_peer_status.sh -H 192.168.253.60 -u root - s PASSWORD -t sip -p T-partner
}
- After that I went to my file newhost.cfg where I have defined my monitorized hosts and the services and add this.
Code: Select all
define service {
use generic-service
host_name asterisk_voip
service_description Custom SIP monitor
check_command check_peer_status
}
- I restart the service and everything seems to work fine, but when I go to the Nagios web interface I find this warning for the service.
Code: Select all
Current Status: WARNING
(for 0d 0h 31m 8s)
Status Information: (No output on stdout) stderr: Traceback (most recent call last):
File "/usr/lib64/nagios/plugins/check_peer_status.sh", line 52, in ?
login = """Action: login\r\nUsername: """ + options.user + """\r\nSecret: """ + options.secret + """\r\nEvents: off\r\n\r\n"""
TypeError: cannot concatenate 'str' and 'NoneType' objects
Code: Select all
[color=#40BF40]Nagios Core 4.0.5
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 04-11-2014
License: GPL
Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Error: Service check command 'check_peer_status.sh' specified in service 'Custom SIP monitor' for host 'asterisk_voip' not defined anywhere!
Checked 29 services.
Checked 6 hosts.
Checked 2 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 26 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 6 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 1
***> One or more problems was encountered while running the pre-flight check...
Check your configuration file(s) to ensure that they contain valid
directives and data defintions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
'Whats New' section to find out what has changed.[/color]
I get the pluggin on http://exchange.nagios.org/directory/Pl ... us/details and this is the script if you want to check it
Code: Select all
[color=#FF0000]#!/usr/bin/python
import os, sys, socket, string
from optparse import *
"""
Check_peer_status plugin for Nagios Copyright (c) 2013 Andrea Zorzetto
Version 0.2.2 updated at 21/11/2013
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
"""
# Process the command line...
parser = OptionParser(usage="Check_peer_status [options]", version="%prog 0.1.0")
parser.set_defaults(hostname='127.0.0.1')
parser.set_defaults(port=5038)
parser.set_defaults(peer="")
parser.add_option("-u", "--username", action="store", dest="user",
help="username for AMI.")
parser.add_option("-s", "--secret", action="store", dest="secret",
help="password for AMI.")
parser.add_option("-H", "--host", action="store", dest="hostname",
help="the host to connect to. The default is localhost.")
parser.add_option("-P", "--port", action="store", dest="port",
help="the port to contact. Default is 5038.")
parser.add_option("-t", "--type", action="store", dest="type",
help="sip or iax are allowed values.")
parser.add_option("-p", "--peer", action="store", dest="peer",
help="the peer name to check.")
parser.add_option("-a", "--all", action="store_true", dest="all",
help="print the whole output.")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
help="print the whole output.")
(options, args) = parser.parse_args()
# Define the socket connection
mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
login = """Action: login\r\nUsername: """ + options.user + """\r\nSecret: """ + options.secret + """\r\nEvents: off\r\n\r\n"""
if (options.type=="sip"):
command="sip show peer"
commandall="sip show peers"
elif (options.type=="iax"):
command="iax2 show peer"
commandall="iax2 show peers"
else:
print "Type peer error"+options.type
sys.exit(1)
if (options.all):
action = """Action: command\r\nCommand: """ + commandall + """\r\n\r\n"""
else:
action = """Action: command\r\nCommand: """ + command + """ """+ options.peer +"""\r\n\r\n"""
logout = """Action: logoff\r\n\r\n"""
#global port
host = options.hostname
port = int(options.port)
user = options.user
password = options.secret
def connect(host, user, password):
mysocket.connect((host, port))
mysocket.send(login)
def disconnect(logout):
send_command(logout)
mysocket.send(logout)
mysocket.close()
def send_command(action):
mysocket.send(action)
global myrcvd
myrcvd = ""
while 1:
data = mysocket.recv(4096) #The output bytes from the socket connection. You can adjust size to taste.
myrcvd = myrcvd + data
#print "$"+ data +"_"
#print len(data)
if (len(data)==0) or (string.find(data,'END COMMAND')>0):
break
return myrcvd
def get_peer_status(myrcvd):
#Search peer status
pos1= string.find(myrcvd,'Status')
pos2= string.find(myrcvd[pos1:],'\n')
#get peer status
status=myrcvd[pos1:]
status=status[:pos2]
return status
# Perform the operation...
try:
connect(host, user, password)
result=send_command(action)
disconnect(logout)
#check auth
if string.find(result,'accepted') != -1:
if (options.all):
print result
elif (options.verbose):
print result
else:
status=get_peer_status(result)
if (string.find(status,'OK') >0):
print status
elif (string.find(status,'LAGGED') >0):
print status
sys.exit(1)
elif (string.find(status,'UNKNOWN') >0):
print status
sys.exit(3)
elif (string.find(status,'unmonitored') >0):
print status
sys.exit(1)
else:
print status
sys.exit(2)
else:
print "Critical - Authentication failed"
sys.exit(2)
sys.exit(0)
except socket.error:
print "Critical - Cannot contact Asterisk!"
sys.exit(2)
[/color]
Kind regards
Please use [ code ] [/code] wraps for all large text amounts