12
12
"""
13
13
14
14
import argparse # pylint: disable=C0413
15
- import flatdict # pylint: disable=C0413
15
+ import json # pylint: disable=C0413
16
16
import sys # pylint: disable=C0413
17
+ import flatdict # pylint: disable=C0413
17
18
18
19
import lib .args # pylint: disable=C0413
19
20
import lib .base # pylint: disable=C0413
@@ -25,7 +26,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
25
26
STATE_UNKNOWN , STATE_WARN )
26
27
27
28
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
28
- __version__ = '2023091401 '
29
+ __version__ = '2023091402 '
29
30
30
31
DESCRIPTION = """Statuspal is a status page provider from Germany. This check plugin gets
31
32
the summary of a Statuspal status page, checks its status, services,
@@ -90,7 +91,7 @@ def concat_values(mydict, hierarchy):
90
91
"""
91
92
result = ''
92
93
hierarchy = hierarchy .split (':' )
93
- for i , item in enumerate (hierarchy ):
94
+ for i , item in enumerate (hierarchy ): # pylint: disable=W0612
94
95
# testing
95
96
# * services:name
96
97
# * services:0:name
@@ -106,6 +107,8 @@ def concat_values(mydict, hierarchy):
106
107
107
108
108
109
def statuspalstate2state (sps ):
110
+ """Convert Statuspal's incident level to the Nagios world.
111
+ """
109
112
if sps is None :
110
113
return STATE_OK
111
114
if sps == 'minor' :
@@ -132,7 +135,6 @@ def main():
132
135
result = lib .base .coe (lib .url .fetch_json (args .URL ))
133
136
else :
134
137
# do not call the command, put in test data
135
- import json
136
138
stdout , stderr , retc = lib .test .test (args .TEST )
137
139
result = json .loads (stdout )
138
140
@@ -144,7 +146,6 @@ def main():
144
146
# init some vars
145
147
msg = ''
146
148
state = statuspalstate2state (result ['status_page' ]['current_incident_type' ])
147
- perfdata = ''
148
149
149
150
# analyze data and build the message
150
151
@@ -174,7 +175,6 @@ def main():
174
175
175
176
# services - search for any incidents in services
176
177
flattened_result = flatdict .FlatterDict (result ['services' ])
177
- old_key = ''
178
178
table_data = []
179
179
tmp = {}
180
180
for key , value in flattened_result .items ():
@@ -187,18 +187,13 @@ def main():
187
187
tmp = {}
188
188
if table_data :
189
189
msg += '\n \n '
190
- keys = [
191
- 'name' ,
192
- 'state' ,
193
- ]
194
- headers = [
195
- 'Service' ,
196
- 'State' ,
197
- ]
198
- msg += lib .base .get_table (table_data , keys , header = headers )
190
+ msg += lib .base .get_table (
191
+ table_data ,
192
+ ['name' , 'state' ],
193
+ header = ['Service' , 'State' ],
194
+ )
199
195
200
196
# maintenance
201
- old_key = ''
202
197
table_data = []
203
198
for maint in result ['maintenances' ]:
204
199
table_data .append ({
@@ -207,29 +202,20 @@ def main():
207
202
'starts_at' : '{}' .format (
208
203
lib .time .timestr2datetime (maint ['starts_at' ], pattern = '%Y-%m-%dT%H:%M:%S' ),
209
204
),
210
- # in case of an ongoing maint, ends_at is "None"
205
+ # in case of an ongoing maint, ends_at is "None"
211
206
'ends_at' : '{}' .format (
212
207
lib .time .timestr2datetime (maint ['ends_at' ], pattern = '%Y-%m-%dT%H:%M:%S' ),
213
208
) if maint .get ('ends_at' ) is not None else 'in progress' ,
214
209
})
215
210
if table_data :
216
211
msg += '\n '
217
- keys = [
218
- 'title' ,
219
- 'type' ,
220
- 'starts_at' ,
221
- 'ends_at' ,
222
- ]
223
- headers = [
224
- 'Maintenance' ,
225
- 'Type' ,
226
- 'Start' ,
227
- 'End' ,
228
- ]
229
- msg += lib .base .get_table (table_data , keys , header = headers )
212
+ msg += lib .base .get_table (
213
+ table_data ,
214
+ ['title' , 'type' , 'starts_at' , 'ends_at' ],
215
+ header = ['Maintenance' , 'Type' , 'Start' , 'End' ],
216
+ )
230
217
231
218
# upcoming_maintenances (just fyi)
232
- old_key = ''
233
219
table_data = []
234
220
for maint in result ['upcoming_maintenances' ]:
235
221
table_data .append ({
@@ -238,29 +224,21 @@ def main():
238
224
'starts_at' : '{}' .format (
239
225
lib .time .timestr2datetime (maint ['starts_at' ], pattern = '%Y-%m-%dT%H:%M:%S' ),
240
226
),
241
- # in case of an ongoing maint, ends_at is "None"
227
+ # in case of an ongoing maint, ends_at is "None"
242
228
'ends_at' : '{}' .format (
243
229
lib .time .timestr2datetime (maint ['ends_at' ], pattern = '%Y-%m-%dT%H:%M:%S' ),
244
230
) if maint .get ('ends_at' ) is not None else 'open end' ,
245
231
})
246
232
if table_data :
247
233
msg += '\n '
248
- keys = [
249
- 'title' ,
250
- 'type' ,
251
- 'starts_at' ,
252
- 'ends_at' ,
253
- ]
254
- headers = [
255
- 'Upcoming Maintenance' ,
256
- 'Type' ,
257
- 'Start' ,
258
- 'End' ,
259
- ]
260
- msg += lib .base .get_table (table_data , keys , header = headers )
234
+ msg += lib .base .get_table (
235
+ table_data ,
236
+ ['title' , 'type' , 'starts_at' , 'ends_at' ],
237
+ header = ['Upcoming Maintenance' , 'Type' , 'Start' , 'End' ],
238
+ )
261
239
262
240
# over and out
263
- lib .base .oao (msg , state , perfdata , always_ok = args .ALWAYS_OK )
241
+ lib .base .oao (msg , state , '' , always_ok = args .ALWAYS_OK )
264
242
265
243
266
244
if __name__ == '__main__' :
0 commit comments