-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_su_fortinet-analyzer-cpu
executable file
·100 lines (79 loc) · 2.26 KB
/
check_su_fortinet-analyzer-cpu
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
#
# Written by Magnus 'Magnux' Svensson 2017-08-30.
#
#################################
# #
# Check for Fortinet Fortigate. #
# CPU #
# #
#################################
from easysnmp import Session
import argparse
import sys
oid_cpu = '1.3.6.1.4.1.12356.103.2.1.1'
print_template = 'cpu: {:.2f} % used'
parser = argparse.ArgumentParser()
parser.add_argument(
'-H',
help = 'Host fqdn is needed!',
required=True,
)
parser.add_argument(
'-C',
help = 'Community is needed!',
required=True,
)
parser.add_argument(
'-c',
help = 'Critical values are needed!',
type=int,
)
parser.add_argument(
'-w',
help = 'warning values are needed!',
type=int,
)
args = parser.parse_args()
my_hostname = args.H
my_community = args.C
warning = args.w
critical = args.c
def check_thresholds(critical, warning):
# check thresholds values
if critical <= warning:
print('Critical is lower or identical with warning, exiting...')
sys.exit(-1)
# Create an SNMP session to be used for all requests
session = Session(hostname=my_hostname, community=my_community, version=2)
# Make the snmpwalk
def retrive_snmp_data(session,oid):
items = session.walk(oid)
for item in items:
return '{value}'.format(value=item.value)
# Check thresholds and exit with appropriate exit code.
def checking(x,warning,critical, print_template):
status = -1
if int(x) == None:
status = -1
elif x < warning and x < critical:
status = 0
elif x >= warning:
status = 1
if x >= critical:
status = 2
if status == 1:
print('WARNING: ' + print_template.format(x))
sys.exit(1)
elif status == 2:
print('CRITICAL: ' + print_template.format(x))
sys.exit(2)
elif status == 0:
print('OK: ' + print_template.format(x))
sys.exit(0)
elif status == -1:
print('UNKNOWN: ' + print_template.format(x))
sys.exit(-1)
check_thresholds(critical, warning)
cpu =retrive_snmp_data(session,oid_cpu)
checking(int(cpu),warning,critical, print_template)