-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_su_fortinet-analyzer-disk
executable file
·109 lines (86 loc) · 2.51 KB
/
check_su_fortinet-analyzer-disk
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
101
102
103
104
105
106
107
108
109
#!/usr/bin/python
#
# Written by Magnus 'Magnux' Svensson 2017-08-30.
#
#################################
# #
# Check for Fortinet Analyzer. #
# DISK #
# #
#################################
from easysnmp import Session
import argparse
import sys
import math
oid_tot = '1.3.6.1.4.1.12356.103.2.1.5'
oid_used = '1.3.6.1.4.1.12356.103.2.1.4'
print_template = 'DISK: {:.2f} % free'
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('Warning is lower or identical with critical, 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)
disk_used = retrive_snmp_data(session,oid_used)
disk_tot =retrive_snmp_data(session,oid_tot)
if not (disk_used or disk_tot):
print("Noooooooo...")
sys.exit(1)
disk_free = ((float(disk_tot) - float(disk_used)) / float(disk_tot) * 100)
checking(disk_free,warning,critical, print_template)