Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / other / prosody @ 7d79f288

Historique | Voir | Annoter | Télécharger (3,1 ko)

1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# Copyright (c) 2010 Christoph Heer (Christoph.Heer@googlemail.com)
4
#
5
# Permission is hereby granted, free of charge, to any person obtaining a
6
# copy of this software and associated documentation files (the \"Software\"),
7
# to deal in the Software without restriction, including without limitation
8
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
# and/or sell copies of the Software, and to permit persons to whom the
10
# Software is furnished to do so, subject to the following conditions:
11
#
12
# The above copyright notice and this permission notice shall be included in
13
# all copies or substantial portions of the Software.
14
#
15
# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
# DEALINGS IN THE SOFTWARE.
22

    
23
import sys
24
import os
25
import telnetlib
26
import re
27

    
28
def main():	
29
	mode = ""
30
	try: mode = sys.argv[1]
31
	except Exception, IndexError: mode = ""
32
	wildcard = sys.argv[0].split("prosody_")[1].split("_")[0]
33
	
34
	if mode == "suggest":
35
		print "c2s"
36
		print "s2s"
37
		sys.exit(0)
38

    
39
	if wildcard == "c2s":
40
		if mode == "config":
41
			print "graph_title Prosody C2S Connections"
42
			print "graph_vlabel users"
43
			print "graph_category Prosody"
44
		
45
			print "all_client_connections.label client connections"
46
			print "secure_client_connections.label secure client connections"
47
			print "insecure_client_connections.label insecure client connections"
48
			sys.exit(0)
49
			
50
		else:
51
			Regex = re.compile(r"Total:\s(\d+)\s")
52
			telnet = telnetlib.Telnet('localhost', 5582)
53
			telnet.write("c2s:show_secure()")
54
			telnetResponse = telnet.read_until("secure client connections", 5)
55
			ParsedInfo = Regex.findall(telnetResponse)
56
			scc = int(ParsedInfo[0])
57
			print "secure_client_connections.value %s" % (scc)
58
			
59
			telnet.write("c2s:show_insecure()")
60
			telnetResponse = telnet.read_until("insecure client connections", 5)
61
			ParsedInfo = Regex.findall(telnetResponse)
62
			icc = int(ParsedInfo[0])
63
			print "insecure_client_connections.value %s" % (icc)
64
			cc = scc + icc
65
			print "all_client_connections.value %s" % (cc)
66
			
67
	elif wildcard == "s2s":
68
		if mode == "config":
69
			print "graph_title Prosody S2S Connections"
70
			print "graph_vlabel servers"
71
			print "graph_category Prosody"
72
		
73
			print "outgoing_connections.label outgoing connections"
74
			print "incoming_connections.label incoming connections"
75
			sys.exit(0)
76
			
77
		else:	
78
			Regex = re.compile(r"(\d+) outgoing, (\d+)")
79
			telnet = telnetlib.Telnet('localhost', 5582)
80
			telnet.write("s2s:show()")
81
			telnetResponse = telnet.read_until("connections", 5)
82
			ParsedInfo = Regex.findall(telnetResponse)
83
			print "outgoing_connections.value %s" % (ParsedInfo[0][0])
84
			print "incoming_connections.value %s" % (ParsedInfo[0][1])
85
		
86
if __name__ == '__main__':
87
	main()