forked from eddimas/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_odoo_mail.py
executable file
·86 lines (75 loc) · 2.29 KB
/
check_odoo_mail.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
86
#!/usr/bin/env python3
import xmlrpc.client
import datetime
import sys
import getopt
class Odoo():
# Funcion para autenticar en odoo
def authenticateOdoo(self,database,mail,secret,port,url):
self.DATA = database # db name
self.USER = mail # email address
self.PASS = secret # password
self.PORT = port # port
self.URL = url # base url
self.URL_COMMON = "{}:{}/xmlrpc/2/common".format(
self.URL, self.PORT)
self.URL_OBJECT = "{}:{}/xmlrpc/2/object".format(
self.URL, self.PORT)
self.ODOO_COMMON = xmlrpc.client.ServerProxy(self.URL_COMMON)
self.ODOO_OBJECT = xmlrpc.client.ServerProxy(self.URL_OBJECT)
self.UID = self.ODOO_COMMON.authenticate(
self.DATA
, self.USER
, self.PASS
, {})
# Funcion para obtener las ordenes del pos segun estado
def mailsCheck(self):
odoo_filter = [[('state', '=', 'exception')]]
mails_id = self.ODOO_OBJECT.execute_kw(
self.DATA
, self.UID
, self.PASS
, 'mail.mail'
, 'search'
, odoo_filter)
return len(mails_id)
def help(self):
print('Usage: check_odoo_fe.py -d database -m mail -s password -p port -u url')
def main(argv):
od = Odoo()
# Si no estan todos los argumentos salir
if len(sys.argv) < 10:
od.help()
sys.exit(2)
try:
opts,args=getopt.getopt(argv,"hd:m:s:p:u:")
except getopt.GetoptError:
od.help()
sys.exit(2)
# Obtener argumentos
for opt, arg in opts:
if opt == '-h':
od.help()
sys.exit(2)
elif opt == '-d':
database = arg
elif opt == '-m':
mail = arg
elif opt == '-s':
secret = arg
elif opt == '-p':
port = arg
elif opt == '-u':
url = arg
od.authenticateOdoo(database,mail,secret,port,url)
# Buscar mails
mails_id = od.mailsCheck()
# Leer detalles de las sesiones
if mails_id == 0:
print('OK - You have '+str(mails_id)+' mails with failed state')
sys.exit(0)
else:
print('CRITICAL - You have '+str(mails_id)+' mails with failed state')
sys.exit(2)
if __name__ == '__main__':
main(sys.argv[1:])