Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

add vhost option #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions scripts/rabbitmq/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
class RabbitMQAPI(object):
'''Class for RabbitMQ Management API'''

def __init__(self, user_name='guest', password='guest', host_name='',
def __init__(self, user_name='guest', password='guest', host_name='', aliveness_vhost='',
port=15672, conf='/etc/zabbix/zabbix_agentd.conf', senderhostname=None, protocol='http'):
self.user_name = user_name
self.password = password
self.host_name = host_name or socket.gethostname()
self.port = port
self.aliveness_vhost = aliveness_vhost or '%2f'
self.conf = conf or '/etc/zabbix/zabbix_agentd.conf'
self.senderhostname = senderhostname
self.protocol = protocol or 'http'
Expand Down Expand Up @@ -194,7 +195,7 @@ def _send_data(self, tmpfile):

def check_aliveness(self):
'''Check the aliveness status of a given vhost.'''
return self.call_api('aliveness-test/%2f')['status']
return self.call_api('aliveness-test/'+self.aliveness_vhost)['status']

def check_server(self, item, node_name):
'''First, check the overview specific items'''
Expand Down Expand Up @@ -233,6 +234,7 @@ def main():
parser.add_option('--hostname', help='RabbitMQ API host', default=socket.gethostname())
parser.add_option('--protocol', help='Use http or https', default='http')
parser.add_option('--port', help='RabbitMQ API port', type='int', default=15672)
parser.add_option('--aliveness_vhost', help='RabbitMQ vhost for check aliveness', default='%2f')
parser.add_option('--check', type='choice', choices=choices, help='Type of check')
parser.add_option('--metric', help='Which metric to evaluate', default='')
parser.add_option('--filters', help='Filter used queues (see README)')
Expand All @@ -248,7 +250,7 @@ def main():

logging.debug("Started trying to process data")
api = RabbitMQAPI(user_name=options.username, password=options.password,
host_name=options.hostname, port=options.port,
host_name=options.hostname, port=options.port, aliveness_vhost=options.aliveness_vhost,
conf=options.conf, senderhostname=options.senderhostname,
protocol=options.protocol)
if options.filters:
Expand Down
9 changes: 7 additions & 2 deletions scripts/rabbitmq/rabbitmq-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ cd "$(dirname "$0")"
TYPE_OF_CHECK=$1
METRIC=$2
NODE=$3
ALIVENESS_VHOST=$4

if [[ -z "$HOSTNAME" ]]; then
HOSTNAME=`hostname`
fi
if [[ -z "$NODE" ]]; then
NODE=`hostname`
NODE='%2f'
fi
if [[ -z "$ALIVENESS_VHOST" ]]; then
ALIVENESS_VHOST='root'
fi
#rabbitmq[queues]
#rabbitmq[server,disk_free]
Expand All @@ -24,4 +28,5 @@ fi
# This assumes that the server is going to then use zabbix_sender to feed the data BACK to the server. Right now, I'm doing that
# in the python script

./api.py --hostname=$HOSTNAME --username=$USERNAME --password=$PASSWORD --check=$TYPE_OF_CHECK --metric=$METRIC --node="$NODE" --filters="$FILTER" --conf=$CONF --loglevel=${LOGLEVEL} --logfile=${LOGFILE} --port=$PORT --protocol=$PROTOCOL
./api.py --hostname=$HOSTNAME --username=$USERNAME --password=$PASSWORD --check=$TYPE_OF_CHECK --metric=$METRIC --node="$NODE" --filters="$FILTER" --conf=$CONF --loglevel=${LOGLEVEL} --logfile=${LOGFILE} --port=$PORT --aliveness_vhost=$ALIVENESS_VHOST --protocol=$PROTOCOL