/
getWowzaInfo.py
85 lines (62 loc) · 1.68 KB
/
getWowzaInfo.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/env python
# Vicente Dominguez
# -a conn - Global connections
# -a appnum - Global application(streaming) num
import urllib2, base64, sys, getopt
import xml.etree.ElementTree as ET
# Default values
username = "admin"
password = "admin"
host = "localhost"
port = "8086"
realm = "Wowza Media Systems"
getInfo = "None"
##
def Usage ():
print "Usage: getWowzaInfo.py -u user -p password -h 127.0.0.1 -P 8086 -a [conn|appnum]"
sys.exit(2)
def getCurrentConnections():
print xmlroot[0].text
def getCurrentStreams():
Application = xmlroot.findall('VHost/Application')
print len(Application)
def unknown():
print "unknown"
##
def main (username,password,host,port,getInfo):
global xmlroot
argv = sys.argv[1:]
if (len(argv) < 1):
Usage()
try :
opts, args = getopt.getopt(argv, "u:p:h:P:a:")
# Assign parameters as variables
for opt, arg in opts :
if opt == "-u" :
username = arg
if opt == "-p" :
password = arg
if opt == "-h" :
host = arg
if opt == "-P" :
port = arg
if opt == "-a" :
getInfo = arg
except :
Usage()
url="http://" + host + ":" + port + "/connectioncounts/"
authhandler = urllib2.HTTPDigestAuthHandler()
authhandler.add_password(realm, url, username, password)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
page_content = urllib2.urlopen(url)
xmlroot = ET.fromstring(page_content.read())
if ( getInfo == "conn"):
getCurrentConnections()
elif ( getInfo == "appnum"):
getCurrentStreams()
else:
unknown()
sys.exit(1)
if __name__ == "__main__":
main(username,password,host,port,getInfo)