-
Notifications
You must be signed in to change notification settings - Fork 8
/
checkSupervisorStatus.py
executable file
·67 lines (56 loc) · 2.23 KB
/
checkSupervisorStatus.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Tart Monitoring
#
# Copyright (c) 2013, Tart İnternet Teknolojileri Ticaret AŞ
#
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
# granted, provided that the above copyright notice and this permission notice appear in all copies.
#
# The software is provided "as is" and the author disclaims all warranties with regard to the software including all
# implied warranties of merchantability and fitness. In no event shall the author be liable for any special, direct,
# indirect, or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether
# in an action of contract, negligence or other tortious action, arising out of or in connection with the use or
# performance of this software.
##
from __future__ import print_function
import sys
import xmlrpclib
def exitCode(state):
if state == 'FATAL':
return 2
if state != 'RUNNING':
return 1
return 0
def main(argv):
if len(argv) < 2:
raise Exception('No argument.')
if len(argv) > 2:
raise Exception('Too many arguments.')
server = xmlrpclib.Server(argv[1])
processes = server.supervisor.getAllProcessInfo()
if not processes:
raise Exception('No process.')
processesByState = {}
for process in processes:
if process['statename'] not in processesByState:
processesByState[process['statename']] = []
processesByState[process['statename']].append(process)
for state in sorted(processesByState, key=exitCode, reverse=True):
print(state, end=': ')
if len(processesByState[state]) / (exitCode(state) + 1) < 5:
for process in processesByState[state]:
print(process['name'], end=' ')
if process.get('description'):
print(process['description'], end=' ')
else:
print(str(len(processesByState[state])) + ' process', end=' ')
print()
return max((exitCode(state) for state in processesByState))
if __name__ == '__main__':
try:
sys.exit(main(sys.argv))
except Exception as exception:
print('Error: ' + str(exception))
sys.exit(3)