Skip to content

Commit 11a82a4

Browse files
author
Carl Chang
committed
add more details to default config;
add support for custom value converters;
1 parent c041598 commit 11a82a4

File tree

4 files changed

+223
-16
lines changed

4 files changed

+223
-16
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@ Fields indicated by `xxxxx` is customizable.
8383
# E.g. each disk item returned. Default is " - ".
8484
"global-oid-separator": "xxxx", # string to separate each sub item in an oid entry.
8585
# E.g. each piece of info of a disk. Default is ", ".
86-
"custom-mappings": {
87-
"xxxxxxxx": { "xx": "ok", "xx": "fail" } # custom logic to convert raw value to standard status values (ok, fail, etc.).
86+
"custom-mappings": { # (optional) custom logic to convert raw value to standard status values (ok, fail, etc.).
87+
"xxxxxxxx": { "xx": "ok", "xx": "fail" },
88+
...
89+
},
90+
"custom-converters": { # (optional) custom python code applied to the oid result.
91+
"xxxxxxxx": "xxxxxxxxxxx{0}xxxxxxx", # the code will be used in eval() and {0} refers to the raw oid result.
92+
...
8893
}
8994
},
9095
"dell": {

check_snmp.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
Config = json.load(config_file, object_pairs_hook=OrderedDict)
3636

3737
CustomMappings = Config['config'].get('custom-mappings') # type: OrderedDict[str, OrderedDict]
38+
CustomConverters = Config['config'].get('custom-converters') # type: OrderedDict[str, str]
3839

3940
StatusOK = Config['config']['status-ok']
4041
StatusWarning = Config['config']['status-warning']
@@ -129,7 +130,8 @@ def get_row_output(col_val_raw: str,
129130
col_type: str,
130131
col_prefix: str = None,
131132
col_suffix: str = None,
132-
col_mapping: str = None) -> str:
133+
col_mapping: str = None,
134+
col_converter: str = None) -> str:
133135
if col_prefix is None: col_prefix = ''
134136
if col_suffix is None: col_suffix = ''
135137
if col_type == 'custom' and col_mapping is None: col_type = 'text'
@@ -141,8 +143,12 @@ def get_row_output(col_val_raw: str,
141143
col_val = status_converter(CustomMappings[col_mapping][col_val_raw])
142144
global category_code
143145
category_code = update_status_code(category_code, col_val)
146+
if col_converter is not None:
147+
col_val_raw = eval(CustomConverters[col_converter].format(col_val_raw)) # apply converter at last
144148
result = status_formatter(col_val, StatusMap[col_val]['status'] + ' (' + col_val_raw + ')', args_MoreFormat)
145149
else:
150+
if col_converter is not None:
151+
col_val_raw = eval(CustomConverters[col_converter].format(col_val_raw)) # apply converter at last
146152
result = col_val_raw
147153
return col_prefix + result + col_suffix
148154

@@ -195,13 +201,14 @@ def get_row_output(col_val_raw: str,
195201
oid['type'],
196202
oid.get('prefix'),
197203
oid.get('suffix'),
198-
oid.get('mapping')) for l in oid_result_raw.stdout.splitlines()])
204+
oid.get('mapping'),
205+
oid.get('converter')) for l in oid_result_raw.stdout.splitlines()])
199206
category_result_raw = [i for i in zip(*category_result_raw)] # swap axis
200207

201208
# generate output
202209
if len(category_result_raw) == 1 and len(category_result_raw[0]) == 1: # there is only one status item without anything else
203210
col = category_result_raw[0][0]
204-
row_output = get_row_output(col[0], col[1], col[2], col[3], col[4])
211+
row_output = get_row_output(col[0], col[1], col[2], col[3], col[4], col[5])
205212
if not args_Brief:
206213
combined_status = row_output
207214
else:
@@ -211,7 +218,7 @@ def get_row_output(col_val_raw: str,
211218
for row in category_result_raw: # row is like (('DIMM.Socket.A1', 'text'), ('failed', 'status'))
212219
cols = []
213220
for col in row: # col is like ('DIMM.Socket.A1', 'text')
214-
cols.append(get_row_output(col[0], col[1], col[2], col[3], col[4]))
221+
cols.append(get_row_output(col[0], col[1], col[2], col[3], col[4], col[5]))
215222

216223
if not args_Brief:
217224
category_output += list_bullet + oid_separator.join(cols) + '\n'

config_default.json

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"global-oid-separator": ", ",
88
"custom-mappings": {
99
"map-boolean": { "0": "ok", "1": "fail" }
10+
},
11+
"custom-converters": {
12+
"str-upper": "str.upper('{0}')",
13+
"floor-divide-1024": "str(round(int('{0}')//1024, 2))",
14+
"floor-divide-1024sq": "str(round(int('{0}')//1048576, 2))",
15+
"floor-divide-10": "str(round(int('{0}')//10, 2))"
1016
}
1117
},
1218
"dell": {
@@ -25,28 +31,37 @@
2531
"processor": {
2632
"description": "Processor Status",
2733
"oids": [
28-
{ "oid": "processorDeviceBrandName", "type": "text" },
34+
{ "oid": "processorDeviceBrandName", "type": "text", "suffix": ", " },
35+
{ "oid": "processorDeviceCoreCount", "type": "text", "suffix": "C " },
36+
{ "oid": "processorDeviceThreadCount", "type": "text", "suffix": "T, " },
2937
{ "oid": "processorDeviceStatus", "type": "status" }
30-
]
31-
},
38+
],
39+
"oid-separator": ""
40+
},
3241
"memory": {
3342
"description": "Memory Status",
3443
"oids": [
3544
{ "oid": "memoryDeviceLocationName", "type": "text" },
45+
{ "oid": "memoryDeviceSize", "type": "text", "suffix": " GB", "converter": "floor-divide-1024sq" },
46+
{ "oid": "memoryDeviceSpeed", "type": "text", "suffix": " MHz" },
3647
{ "oid": "memoryDeviceStatus", "type": "status" }
3748
]
3849
},
3950
"physicalDisk": {
4051
"description": "Physical Disk Status",
4152
"oids": [
42-
{ "oid": "physicalDiskDisplayName", "type": "text" },
43-
{ "oid": "physicalDiskState", "type": "status", "prefix": " - Health: " },
44-
{ "oid": "physicalDiskSmartAlertIndication", "type": "custom", "prefix": " - Failing: ", "mapping": "map-boolean" },
45-
{ "oid": "physicalDiskOperationalState", "type": "status", "prefix": " - Operation: " },
53+
{ "oid": "physicalDiskDisplayName", "type": "text", "suffix": "\n" },
54+
{ "oid": "physicalDiskManufacturer", "type": "text", "prefix": " - Info: ", "suffix": " ", "converter": "str-upper" },
55+
{ "oid": "physicalDiskBusType", "type": "text", "suffix": " ", "converter": "str-upper" },
56+
{ "oid": "physicalDiskMediaType", "type": "text", "suffix": " ", "converter": "str-upper" },
57+
{ "oid": "physicalDiskCapacityInMB", "type": "text", "suffix": " GB\n", "converter": "floor-divide-1024" },
58+
{ "oid": "physicalDiskState", "type": "status", "prefix": " - Health: ", "suffix": "\n" },
59+
{ "oid": "physicalDiskSmartAlertIndication", "type": "custom", "prefix": " - Failing: ", "suffix": "\n", "mapping": "map-boolean" },
60+
{ "oid": "physicalDiskOperationalState", "type": "status", "prefix": " - Operation: ", "suffix": "\n" },
4661
{ "oid": "physicalDiskProgress", "type": "text", "prefix": " - Progress: " }
4762
],
4863
"list-bullet": " + ",
49-
"oid-separator": "\n"
64+
"oid-separator": ""
5065
},
5166
"virtualDisk": {
5267
"description": "Virtual Disk Status",
@@ -66,24 +81,41 @@
6681
{ "oid": "controllerComponentStatus", "type": "status" }
6782
]
6883
},
69-
"cooling": {
70-
"description": "Cooling Status",
84+
"coolingUnit": {
85+
"description": "Cooling Unit Status",
7186
"oids": [
7287
{ "oid": "coolingUnitName", "type": "text" },
7388
{ "oid": "coolingUnitStatus", "type": "status" }
7489
]
7590
},
91+
"coolingDevice": {
92+
"description": "Cooling Device Status",
93+
"oids": [
94+
{ "oid": "coolingDeviceLocationName", "type": "text" },
95+
{ "oid": "coolingDeviceReading", "type": "text", "suffix": " RPM" },
96+
{ "oid": "coolingDeviceStatus", "type": "status" }
97+
]
98+
},
7699
"temperature": {
77100
"description": "Temperature Status",
78101
"oids": [
79102
{ "oid": "temperatureProbeLocationName", "type": "text" },
103+
{ "oid": "temperatureProbeReading", "type": "text", "converter": "floor-divide-10", "suffix": " °C" },
80104
{ "oid": "temperatureProbeStatus", "type": "status" }
81105
]
82106
},
107+
"powerUnit": {
108+
"description": "Power Unit Status",
109+
"oids": [
110+
{ "oid": "powerUnitName", "type": "text" },
111+
{ "oid": "powerUnitStatus", "type": "status" }
112+
]
113+
},
83114
"powerSupply": {
84115
"description": "Power Supply Status",
85116
"oids": [
86117
{ "oid": "powerSupplyLocationName", "type": "text" },
118+
{ "oid": "powerSupplyCurrentInputVoltage", "type": "text", "suffix": " V" },
87119
{ "oid": "powerSupplyStatus", "type": "status" }
88120
]
89121
},

config_standard.json

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
{
2+
"config": {
3+
"status-ok": [ "ok", "true", "yes", "on", "online", "spunup", "full", "ready", "enabled", "presence", "non-raid", "nonraid", "0", "notapplicable" ],
4+
"status-warning": [ "noncritical", "removed", "foreign", "offline", "rebuild" ],
5+
"status-critical": [ "fail", "failed", "critical", "nonrecoverable", "notredundant", "lost", "degraded", "redundancyoffline" ],
6+
"global-list-bullet": " - ",
7+
"global-oid-separator": ", "
8+
},
9+
"dell": {
10+
"mib_dir": "mibs/default:mibs/iana:mibs/ietf:mibs/dell",
11+
"mib": "IDRAC-MIB-SMIv2",
12+
"categories": {
13+
"global": {
14+
"description": "Overall System Status",
15+
"oids": [
16+
{ "oid": "systemModelName", "type": "text" },
17+
{ "oid": "systemServiceTag", "type": "text" },
18+
{ "oid": "globalSystemStatus", "type": "status" }
19+
],
20+
"important": true
21+
},
22+
"processor": {
23+
"description": "Processor Status",
24+
"oids": [
25+
{ "oid": "processorDeviceBrandName", "type": "text" },
26+
{ "oid": "processorDeviceStatus", "type": "status" }
27+
]
28+
},
29+
"memory": {
30+
"description": "Memory Status",
31+
"oids": [
32+
{ "oid": "memoryDeviceLocationName", "type": "text" },
33+
{ "oid": "memoryDeviceStatus", "type": "status" }
34+
]
35+
},
36+
"physicalDisk": {
37+
"description": "Physical Disk Status",
38+
"oids": [
39+
{ "oid": "physicalDiskDisplayName", "type": "text" },
40+
{ "oid": "physicalDiskState", "type": "status" }
41+
]
42+
},
43+
"virtualDisk": {
44+
"description": "Virtual Disk Status",
45+
"oids": [
46+
{ "oid": "virtualDiskDisplayName", "type": "text" },
47+
{ "oid": "virtualDiskState", "type": "status" }
48+
]
49+
},
50+
"storageController": {
51+
"description": "Storage Controller Status",
52+
"oids": [
53+
{ "oid": "controllerName", "type": "text" },
54+
{ "oid": "controllerComponentStatus", "type": "status" }
55+
]
56+
},
57+
"cooling": {
58+
"description": "Cooling Status",
59+
"oids": [
60+
{ "oid": "coolingUnitName", "type": "text" },
61+
{ "oid": "coolingUnitStatus", "type": "status" }
62+
]
63+
},
64+
"temperature": {
65+
"description": "Temperature Status",
66+
"oids": [
67+
{ "oid": "temperatureProbeLocationName", "type": "text" },
68+
{ "oid": "temperatureProbeStatus", "type": "status" }
69+
]
70+
},
71+
"powerSupply": {
72+
"description": "Power Supply Status",
73+
"oids": [
74+
{ "oid": "powerSupplyLocationName", "type": "text" },
75+
{ "oid": "powerSupplyStatus", "type": "status" }
76+
]
77+
},
78+
"battery": {
79+
"description": "Battery Status",
80+
"oids": [
81+
{ "oid": "systemBatteryLocationName", "type": "text" },
82+
{ "oid": "systemBatteryStatus", "type": "status" }
83+
]
84+
}
85+
}
86+
},
87+
"hpe": {
88+
"mib_dir": "mibs/default:mibs/iana:mibs/ietf:mibs/hpe",
89+
"mib": "CPQSINFO-MIB:CPQHLTH-MIB:CPQIDA-MIB:CPQSTDEQ-MIB",
90+
"categories": {
91+
"global": {
92+
"description": "Overall System Status",
93+
"oids": [
94+
{ "oid": "cpqSiProductName", "type": "text" },
95+
{ "oid": "cpqSiSysSerialNum", "type": "text" },
96+
{ "oid": "cpqHeMibCondition", "type": "status" }
97+
],
98+
"important": true
99+
},
100+
"processor": {
101+
"description": "Processor Status",
102+
"oids": [
103+
{ "oid": "cpqSeCpuName", "type": "text" },
104+
{ "oid": "cpqSeCpuStatus", "type": "status" }
105+
]
106+
},
107+
"memory": {
108+
"description": "Memory Status",
109+
"oids": [
110+
{ "oid": "cpqHeResMem2ModuleHwLocation", "type": "text" },
111+
{ "oid": "cpqHeResMem2ModuleCondition", "type": "status" }
112+
]
113+
},
114+
"physicalDisk": {
115+
"description": "Physical Disk Status",
116+
"oids": [
117+
{ "oid": "cpqDaPhyDrvLocationString", "type": "text" },
118+
{ "oid": "cpqDaPhyDrvCondition", "type": "status" }
119+
]
120+
},
121+
"virtualDisk": {
122+
"description": "Virtual Disk Status",
123+
"oids": [
124+
{ "oid": "cpqDaLogDrvCondition", "type": "status" }
125+
]
126+
},
127+
"storageController": {
128+
"description": "Storage Controller Status",
129+
"oids": [
130+
{ "oid": "cpqDaCntlrModel", "type": "text" },
131+
{ "oid": "cpqDaCntlrCondition", "type": "status" }
132+
]
133+
},
134+
"cooling": {
135+
"description": "Cooling Status",
136+
"oids": [
137+
{ "oid": "cpqHeFltTolFanLocale", "type": "text" },
138+
{ "oid": "cpqHeFltTolFanCondition", "type": "status" }
139+
]
140+
},
141+
"temperature": {
142+
"description": "Temperature Status",
143+
"oids": [
144+
{ "oid": "cpqHeTemperatureLocale", "type": "text" },
145+
{ "oid": "cpqHeTemperatureCondition", "type": "status" }
146+
]
147+
},
148+
"powerSupply": {
149+
"description": "Power Supply Status",
150+
"oids": [
151+
{ "oid": "cpqHeFltTolPowerSupplyModel", "type": "text" },
152+
{ "oid": "cpqHeFltTolPowerSupplyCondition", "type": "status" }
153+
]
154+
},
155+
"eventLog": {
156+
"description": "Integrated Management Log Status",
157+
"oids": [
158+
{ "oid": "cpqHeEventLogCondition", "type": "status" }
159+
]
160+
}
161+
}
162+
}
163+
}

0 commit comments

Comments
 (0)