Skip to content
This repository was 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 1 commit
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='', vhost_name='',
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.vhost_name = vhost_name or 'root'
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.vhost_name)['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('--vhost', help='RabbitMQ vhost', default='root')
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, vhost_name=options.vhost,
conf=options.conf, senderhostname=options.senderhostname,
protocol=options.protocol)
if options.filters:
Expand Down
7 changes: 6 additions & 1 deletion scripts/rabbitmq/rabbitmq-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ cd "$(dirname "$0")"
TYPE_OF_CHECK=$1
METRIC=$2
NODE=$3
VHOST=$4

if [[ -z "$HOSTNAME" ]]; then
HOSTNAME=`hostname`
fi
if [[ -z "$NODE" ]]; then
NODE=`hostname`
fi
if [[ -z "$VHOST" ]]; then
VHOST='root'
fi
#rabbitmq[queues]
#rabbitmq[server,disk_free]
#rabbitmq[check_aliveness]

# 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 --vhost=$VHOST --protocol=$PROTOCOL