-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrabbitqu.py
More file actions
50 lines (43 loc) · 1.8 KB
/
rabbitqu.py
File metadata and controls
50 lines (43 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
import sys
import requests
def getargs(my_args):
if '--help' in my_args:
print 'Help for rabbit queue script:\n', \
'Use this arguments for get length of queue:\n', \
'--host \n--port \n--vhost \n--queue \n--user \n--password', \
'\n--output simple or telegraf', \
'\n telegraf output like a DB, host, queue etc', \
'\n --measurment for telegraf influxdb'
sys.exit(1)
know_args = {'--host': '', '--port': '', '--vhost': '',
'--queue': '', '--user': '', '--password': '',
'--output': 'simple', '--database': ''}
for i in my_args:
if i in know_args.keys():
know_args[i] = my_args[my_args.index(i) + 1]
return know_args
if __name__ == '__main__':
# the one string below maybe delete
test_arg = ['0', '--host', '172.33.1.1', '--port', '15672',
'--vhost', 'qa_vi', '--queue', 'dev_todo',
'--user', 'monitor', '--password', 'monitor_pass',
'--output', 'telegraf', '--database', 'devrabbit']
a = getargs(sys.argv)
if len(sys.argv) < 17:
print 'Too few params (need 8), try --help'
sys.exit(1)
url = 'http://' + a['--host'] + ':' + a['--port'] + '/api/queues/' + \
a['--vhost'] + '/' + a['--queue']
r = requests.get(url, auth=(a['--user'], a['--password']))
if r.status_code == 200:
if a['--output'] == 'simple':
print r.json()['messages']
elif a['--output'] == 'telegraf':
print a['--database'] + ','+'host='+a['--host']+',' \
+'vhost=' + a['--vhost'] + ' ' + a['--queue'] \
+ '='+str(r.json()['messages'])
sys.exit(0)
else:
print 'Error ' + str(r.status_code)
sys.exit(1)