-
Notifications
You must be signed in to change notification settings - Fork 20
/
mapping.py
4561 lines (4503 loc) · 201 KB
/
mapping.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2009-2012:
# Gabes Jean, naparuba@gmail.com
# Gerhard Lausser, Gerhard.Lausser@consol.de
# Gregory Starck, g.starck@gmail.com
# Hartmut Goebel, h.goebel@goebel-consult.de
#
# This file is part of Shinken.
#
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Shinken is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
import os
import re
from shinken.bin import VERSION
from shinken.macroresolver import MacroResolver
from shinken.util import get_customs_keys, get_customs_values
from shinken.objects.host import Host
from shinken.objects.hostgroup import Hostgroup
from shinken.objects.service import Service
from shinken.objects.servicegroup import Servicegroup
from shinken.objects.contact import Contact
from shinken.objects.contactgroup import Contactgroup
from shinken.objects.timeperiod import Timeperiod
from shinken.objects.command import Command
from shinken.objects.config import Config
from shinken.downtime import Downtime
from shinken.comment import Comment
# TODO : in some later version, change those import to new package path of these XxxLink classes:
# from shinken.objects.schedulerlink import SchedulerLink
from shinken.schedulerlink import SchedulerLink
from shinken.reactionnerlink import ReactionnerLink
from shinken.brokerlink import BrokerLink
from shinken.receiverlink import ReceiverLink
from shinken.pollerlink import PollerLink
from shinken.log import logger
from log_line import LOGCLASS_INFO, LOGCLASS_ALERT, LOGCLASS_PROGRAM, LOGCLASS_NOTIFICATION, LOGCLASS_PASSIVECHECK, LOGCLASS_COMMAND, LOGCLASS_STATE, LOGCLASS_INVALID, LOGCLASS_ALL, LOGOBJECT_INFO, LOGOBJECT_HOST, LOGOBJECT_SERVICE, LOGOBJECT_CONTACT, Logline, LoglineWrongFormat
from shinken.misc.common import DICT_MODATTR
class Problem:
def __init__(self, source, impacts):
self.source = source
self.impacts = impacts
def modified_attributes_names(self):
names_list = set()
for attr in DICT_MODATTR:
if self.modified_attributes & DICT_MODATTR[attr].value:
names_list.add(DICT_MODATTR[attr].attribute)
return list(names_list)
def join_with_separators(request, *args):
if request.response.outputformat == 'csv':
try:
return request.response.separators.pipe.join([str(arg) for arg in args])
except Exception, e:
logger.error("[Livestatus Broker Mapping] Bang Error: %s" % e)
elif request.response.outputformat == 'json' or request.response.outputformat == 'python':
return args
else:
return None
pass
def worst_host_state(state_1, state_2):
"""Return the worst of two host states."""
#lambda x: reduce(lambda g, c: c if g == 0 else (c if c == 1 else g), (y.state_id for y in x), 0),
if state_2 == 0:
return state_1
if state_1 == 1:
return state_1
return state_2
def worst_service_state(state_1, state_2):
"""Return the worst of two service states."""
#reduce(lambda g, c: c if g == 0 else (c if c == 2 else (c if (c == 3 and g != 2) else g)), (z.state_id for y in x for z in y.services if z.state_type_id == 1), 0),
if state_2 == 0:
return state_1
if state_1 == 2:
return state_1
if state_1 == 3 and state_2 != 2:
return state_1
return state_2
def find_pnp_perfdata_xml(name, request):
"""Check if a pnp xml file exists for a given host or service name."""
if request.pnp_path_readable:
if '/' in name:
# It is a service
# replace space, colon, slash and backslash to be PNP compliant
name = name.split('/', 1)
name[1] = re.sub(r'[ :\/\\]', '_', name[1])
if os.access(request.pnp_path + '/' + '/'.join(name) + '.xml', os.R_OK):
return 1
else:
# It is a host
if os.access(request.pnp_path + '/' + name + '/_HOST_.xml', os.R_OK):
return 1
# If in doubt, there is no pnp file
return 0
def from_svc_hst_distinct_lists(dct):
"""Transform a dict with keys hosts and services to a list."""
t = []
for item in dct:
try:
t.append(item.get_full_name())
except Exception:
t.append(item.get_name())
return t
def get_livestatus_full_name(item, req):
"""Returns a host's or a service's name in livestatus notation.
This function takes either a host or service object as it's first argument.
The third argument is a livestatus request object. The important information
in the request object is the separators array. It contains the character
that separates host_name and service_description which is used for services'
names with the csv output format. If the output format is json, services' names
are lists composed of host_name and service_description.
"""
cls_name = item.__class__.my_type
if req.response.outputformat == 'csv':
if cls_name == 'service':
return item.host_name + req.response.separators.pipe + item.service_description
else:
return item.host_name
elif req.response.outputformat == 'json' or req.response.outputformat == 'python':
if cls_name == 'service':
return [item.host_name, item.service_description]
else:
return item.host_name
pass
# description (optional): no need to explain this
# prop (optional): the property of the object. If this is missing, the key is the property
# type (mandatory): int, float, string, list
# depythonize: use it if the property needs to be post-processed.
# fulldepythonize: the same, but the postprocessor takes three arguments. property, object, request
# delegate: get the property of a different object
# as: use it together with delegate, if the property of the other object has another name
# description
# function: a lambda with 2 parameters (host/service/comment.., request)
# repr: the datatype returned by the lambda (bool, int, string, list)
# this is needed for filters. lsl query attributes are converted to this datatype
# later, the repr datatype needs to be converted to a string
livestatus_attribute_map = {
'Host': {
'accept_passive_checks': {
'description': 'Whether passive host checks are accepted (0/1)',
'function': lambda item, req: item.passive_checks_enabled,
'datatype': bool,
},
'acknowledged': {
'description': 'Whether the current host problem has been acknowledged (0/1)',
'function': lambda item, req: item.problem_has_been_acknowledged,
'datatype': bool,
},
'acknowledgement_type': {
'description': 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
'function': lambda item, req: item.acknowledgement_type,
'datatype': int,
},
'action_url': {
'description': 'An optional URL to custom actions or information about this host',
'function': lambda item, req: item.action_url,
},
'action_url_expanded': {
'description': 'The same as action_url, but with the most important macros expanded',
'function': lambda item, req: MacroResolver().resolve_simple_macros_in_string(item.action_url, item.get_data_for_checks()),
},
'active_checks_enabled': {
'description': 'Whether active checks are enabled for the host (0/1)',
'function': lambda item, req: item.active_checks_enabled,
'datatype': bool,
},
'address': {
'description': 'IP address',
'function': lambda item, req: item.address,
},
'alias': {
'description': 'An alias name for the host',
'function': lambda item, req: item.alias,
},
'business_impact': {
'description': 'The importance we gave to this host between the minimum 0 and the maximum 5',
'function': lambda item, req: item.business_impact,
'datatype': int,
},
'check_command': {
'description': 'Nagios command for active host check of this host',
'function': lambda item, req: item.check_command.get_name(),
},
'check_flapping_recovery_notification': {
'description': 'Whether to check to send a recovery notification when flapping stops (0/1)',
'function': lambda item, req: item.check_flapping_recovery_notification, # REPAIRME WTF
'datatype': int,
},
'check_freshness': {
'description': 'Whether freshness checks are activated (0/1)',
'function': lambda item, req: item.check_freshness,
'datatype': bool,
},
'check_interval': {
'description': 'Number of basic interval lengths between two scheduled checks of the host',
'function': lambda item, req: item.check_interval,
'datatype': float,
},
'check_options': {
'description': 'The current check option, forced, normal, freshness... (0-2)',
'function': lambda item, req: "", # REPAIRME
'datatype': int,
},
'check_period': {
'description': 'Time period in which this host will be checked. If empty then the host will always be checked.',
'function': lambda item, req: item.check_period.get_name(),
},
'check_type': {
'description': 'Type of check (0: active, 1: passive)',
'function': lambda item, req: item.check_type,
'datatype': int,
},
'checks_enabled': {
'description': 'Whether checks of the host are enabled (0/1)',
'function': lambda item, req: item.active_checks_enabled,
'datatype': bool,
},
'child_dependencies': {
'description': 'List of the host/service that depend on this host (logical, network or business one).',
'function': lambda item, req: from_svc_hst_distinct_lists(item.child_dependencies),
'datatype': list,
},
'childs': {
'description': 'A list of all direct childs of the host',
'function': lambda item, req: [x.get_name() for x in item.childs],
'datatype': list,
},
'comments': {
'description': 'A list of the ids of all comments of this host',
'function': lambda item, req: [x.id for x in item.comments],
'datatype': list,
},
'comments_with_info': {
'description': 'A list of the ids of all comments of this host with id, author and comment',
'function': lambda item, req: [join_with_separators(req, str(x.id), x.author, x.comment) for x in item.comments], # REPAIRME MAYBE
'datatype': list,
},
'contacts': {
'description': 'A list of all contacts of this host, either direct or via a contact group',
'function': lambda item, req: [x.contact_name for x in item.contacts],
'datatype': list,
},
'contact_groups': {
'description': 'A list of all contact groups this host is in',
'function': lambda item, req: item.contact_groups,
'datatype': list,
},
'criticity': {
'description': 'The importance we gave to this host between the minimum 0 and the maximum 5',
'function': lambda item, req: item.business_impact,
'datatype': int,
},
'current_attempt': {
'description': 'Number of the current check attempts',
'function': lambda item, req: item.attempt,
'datatype': int,
},
'current_notification_number': {
'description': 'Number of the current notification',
'function': lambda item, req: item.current_notification_number,
'datatype': int,
},
'custom_variable_names': {
'description': 'A list of the names of all custom variables',
'function': lambda item, req: get_customs_keys(item.customs),
'datatype': list,
},
'custom_variable_values': {
'description': 'A list of the values of the custom variables',
'function': lambda item, req: get_customs_values(item.customs),
'datatype': list,
},
'custom_variables': {
'description': 'A dictionary of the custom variables',
'function': lambda item, req: [join_with_separators(req, k[1:], v) for k, v in item.customs.iteritems()],
'datatype': list,
},
'display_name': {
'description': 'Optional display name of the host - not used by Nagios\' web interface',
'function': lambda item, req: item.display_name,
},
'downtimes': {
'description': 'A list of the ids of all scheduled downtimes of this host',
'function': lambda item, req: [x.id for x in item.downtimes],
'datatype': list,
},
'downtimes_with_info': {
'description': 'A list of the all scheduled downtimes of the host with id, author and comment',
'function': lambda item, req: [join_with_separators(req, str(x.id), x.author, x.comment) for x in item.downtimes], # REPAIRME MAYBE
'datatype': list,
# 2|omdadmin|hdodo = id|author|comment
},
'event_handler': {
'description': 'Nagios command used as event handler',
'function': lambda item, req: item.event_handler.get_name(),
},
'event_handler_enabled': {
'description': 'Whether event handling is enabled (0/1)',
'function': lambda item, req: item.event_handler_enabled,
'datatype': bool,
},
'execution_time': {
'description': 'Time the host check needed for execution',
'function': lambda item, req: item.execution_time,
'datatype': float,
},
'filename': {
'description': 'The value of the custom variable FILENAME',
'function': lambda item, req: '', # REPAIRME
'datatype': str,
},
'first_notification_delay': {
'description': 'Delay before the first notification',
'function': lambda item, req: item.first_notification_delay,
'datatype': float,
},
'flap_detection_enabled': {
'description': 'Whether flap detection is enabled (0/1)',
'function': lambda item, req: item.flap_detection_enabled,
'datatype': bool,
},
'got_business_rule': {
'description': 'Whether the host state is an business rule based host or not (0/1)',
'function': lambda item, req: item.got_business_rule,
'datatype': bool,
},
'groups': {
'description': 'A list of all host groups this host is in',
'function': lambda item, req: [x.get_name() for x in item.hostgroups],
'datatype': list,
},
'hard_state': {
'description': 'The effective hard state of the host (eliminates a problem in hard_state)',
'function': lambda item, req: "", # REPAIRME
'datatype': int,
},
'has_been_checked': {
'description': 'Whether the host has already been checked (0/1)',
'function': lambda item, req: item.has_been_checked,
'datatype': int,
},
'high_flap_threshold': {
'description': 'High threshold of flap detection',
'function': lambda item, req: item.high_flap_threshold,
'datatype': float,
},
'icon_image': {
'description': 'The name of an image file to be used in the web pages',
'function': lambda item, req: item.icon_image,
},
'icon_image_alt': {
'description': 'Alternative text for the icon_image',
'function': lambda item, req: item.icon_image_alt,
},
'icon_image_expanded': {
'description': 'The same as icon_image, but with the most important macros expanded',
'function': lambda item, req: MacroResolver().resolve_simple_macros_in_string(item.icon_image, item.get_data_for_checks()),
},
'impacts': {
'description': 'List of what the source impact (list of hosts and services)',
'function': lambda item, req: [get_livestatus_full_name(i, req) for i in item.impacts], # REPAIRME MAYBE (separators in python and csv)
'datatype': list,
},
'in_check_period': {
'description': 'Whether this host is currently in its check period (0/1)',
'function': lambda item, req: (item.check_period is None and [False] or [item.check_period.is_time_valid(req.tic)])[0],
'datatype': bool,
},
'in_notification_period': {
'description': 'Whether this host is currently in its notification period (0/1)',
'function': lambda item, req: (item.notification_period is None and [False] or [item.notification_period.is_time_valid(req.tic)])[0],
'datatype': bool,
},
'initial_state': {
'description': 'Initial host state',
'function': lambda item, req: item.initial_state,
'datatype': int,
},
'is_executing': {
'description': 'is there a host check currently running... (0/1)',
'function': lambda item, req: False, # REPAIRME # value in scheduler is not real-time
'datatype': bool,
},
'is_flapping': {
'description': 'Whether the host state is flapping (0/1)',
'function': lambda item, req: item.is_flapping,
'datatype': bool,
},
'is_impact': {
'description': 'Whether the host state is an impact or not (0/1)',
'function': lambda item, req: item.is_impact,
'datatype': bool,
},
'is_problem': {
'description': 'Whether the host state is a problem or not (0/1)',
'function': lambda item, req: item.is_problem,
'datatype': bool,
},
'labels': {
'description': 'Arbitrary labels (separated by comma character)',
'function': lambda item, req: item.labels,
'datatype': list,
},
'last_check': {
'description': 'Time of the last check (Unix timestamp)',
'function': lambda item, req: int(item.last_chk),
'datatype': int,
},
'last_hard_state': {
'description': 'Last hard state',
'function': lambda item, req: item.last_hard_state_id,
'datatype': int,
},
'last_hard_state_change': {
'description': 'Time of the last hard state change (Unix timestamp)',
'function': lambda item, req: item.last_hard_state_change,
'datatype': int,
},
'last_notification': {
'description': 'Time of the last notification (Unix timestamp)',
'function': lambda item, req: int(item.last_notification),
'datatype': int,
},
'last_state': {
'description': 'State before last state change',
'function': lambda item, req: item.last_state,
'datatype': int,
},
'last_state_change': {
'description': 'Time of the last state change - soft or hard (Unix timestamp)',
'function': lambda item, req: int(item.last_state_change),
'datatype': int,
},
'last_time_down': {
'description': 'The last time the host was DOWN (Unix timestamp)',
'function': lambda item, req: item.last_time_down, # REPAIRME
'datatype': int,
},
'last_time_unreachable': {
'description': 'The last time the host was UNREACHABLE (Unix timestamp)',
'function': lambda item, req: item.last_time_unreachable, # REPAIRME
'datatype': int,
},
'last_time_up': {
'description': 'The last time the host was UP (Unix timestamp)',
'function': lambda item, req: item.last_time_up, # REPAIRME
'datatype': int,
},
'latency': {
'description': 'Time difference between scheduled check time and actual check time',
'function': lambda item, req: item.latency,
'datatype': float,
},
'long_plugin_output': {
'description': 'Complete output from check plugin',
'function': lambda item, req: item.long_output,
},
'low_flap_threshold': {
'description': 'Low threshold of flap detection',
'function': lambda item, req: item.low_flap_threshold,
'datatype': float,
},
'max_check_attempts': {
'description': 'Max check attempts for active host checks',
'function': lambda item, req: item.max_check_attempts,
'datatype': int,
},
'modified_attributes': {
'description': 'A bitmask specifying which attributes have been modified',
'function': lambda item, req: item.modified_attributes, # CONTROLME
'datatype': int,
},
'modified_attributes_list': {
'description': 'A list of all modified attributes',
'function': lambda item, req: modified_attributes_names(item), # CONTROLME
'datatype': list,
},
'name': {
'description': 'Host name',
'function': lambda item, req: item.host_name,
},
'next_check': {
'description': 'Scheduled time for the next check (Unix timestamp)',
'function': lambda item, req: int(item.next_chk),
'datatype': int,
},
'next_notification': {
'description': 'Time of the next notification (Unix timestamp)',
'function': lambda item, req: int(item.last_notification + item.notification_interval * item.__class__.interval_length), # CONTROLME
'datatype': int,
},
'notes': {
'description': 'Optional notes for this host',
'function': lambda item, req: item.notes,
},
'notes_expanded': {
'description': 'The same as notes, but with the most important macros expanded',
'function': lambda item, req: MacroResolver().resolve_simple_macros_in_string(item.notes, item.get_data_for_checks()),
},
'notes_url': {
'description': 'An optional URL with further information about the host',
'function': lambda item, req: item.notes_url,
},
'notes_url_expanded': {
'description': 'Same es notes_url, but with the most important macros expanded',
'function': lambda item, req: MacroResolver().resolve_simple_macros_in_string(item.notes_url, item.get_data_for_checks()),
},
'notification_interval': {
'description': 'Interval of periodic notification or 0 if its off',
'function': lambda item, req: item.notification_interval,
'datatype': float,
},
'notification_period': {
'description': 'Time period in which problems of this host will be notified. If empty then notification will be always',
'function': lambda item, req: item.notification_period.get_name(),
},
'notifications_enabled': {
'description': 'Whether notifications of the host are enabled (0/1)',
'function': lambda item, req: item.notifications_enabled,
'datatype': bool,
},
'no_more_notifications': {
'description': 'Whether to stop sending notifications (0/1)',
'function': lambda item, req: item.no_more_notifications, # REPAIRME, maybe ask both instance and class
'datatype': bool,
},
'num_services': {
'description': 'The total number of services of the host',
'function': lambda item, req: len(item.services),
},
'num_services_crit': {
'description': 'The number of the host\'s services with the soft state CRIT',
'function': lambda item, req: len([x for x in item.services if x.state_id == 2]),
},
'num_services_hard_crit': {
'description': 'The number of the host\'s services with the hard state CRIT',
'function': lambda item, req: len([x for x in item.services if x.state_id == 2 and x.state_type_id == 1]),
},
'num_services_hard_ok': {
'description': 'The number of the host\'s services with the hard state OK',
'function': lambda item, req: len([x for x in item.services if x.state_id == 0 and x.state_type_id == 1]),
},
'num_services_hard_unknown': {
'description': 'The number of the host\'s services with the hard state UNKNOWN',
'function': lambda item, req: len([x for x in item.services if x.state_id == 3 and x.state_type_id == 1]),
},
'num_services_hard_warn': {
'description': 'The number of the host\'s services with the hard state WARN',
'function': lambda item, req: len([x for x in item.services if x.state_id == 1 and x.state_type_id == 1]),
},
'num_services_ok': {
'description': 'The number of the host\'s services with the soft state OK',
'function': lambda item, req: len([x for x in item.services if x.state_id == 0]),
},
'num_services_pending': {
'description': 'The number of the host\'s services which have not been checked yet (pending)',
'function': lambda item, req: len([x for x in item.services if x.has_been_checked == 0]),
},
'num_services_unknown': {
'description': 'The number of the host\'s services with the soft state UNKNOWN',
'function': lambda item, req: len([x for x in item.services if x.state_id == 3]),
},
'num_services_warn': {
'description': 'The number of the host\'s services with the soft state WARN',
'function': lambda item, req: len([x for x in item.services if x.state_id == 1]),
},
'obsess_over_host': {
'description': 'The current obsess_over_host setting... (0/1)',
'function': lambda item, req: item.obsess_over_host,
'datatype': bool,
},
'parent_dependencies': {
'description': 'List of the dependencies (logical, network or business one) of this host.',
'function': lambda item, req: from_svc_hst_distinct_lists(item.parent_dependencies),
'datatype': list,
},
'parents': {
'description': 'A list of all direct parents of the host',
'function': lambda item, req: [x.get_name() for x in item.parents],
'datatype': list,
},
'pending_flex_downtime': {
'description': 'Whether a flex downtime is pending (0/1)',
'function': lambda item, req: item.pending_flex_downtime,
'datatype': int,
},
'percent_state_change': {
'description': 'Percent state change',
'function': lambda item, req: item.percent_state_change,
'datatype': float,
},
'perf_data': {
'description': 'Optional performance data of the last host check',
'function': lambda item, req: item.perf_data,
},
'plugin_output': {
'description': 'Output of the last host check',
'function': lambda item, req: item.output,
},
'pnpgraph_present': {
'description': 'Whether there is a PNP4Nagios graph present for this host (0/1)',
'function': lambda item, req: find_pnp_perfdata_xml(item.get_name(), req),
'datatype': int,
},
'poller_tag': {
'description': 'Poller Tag',
'function': lambda item, req: item.poller_tag,
},
'process_performance_data': {
'description': 'Whether processing of performance data is enabled (0/1)',
'function': lambda item, req: item.process_perf_data,
'datatype': bool,
},
'realm': {
'description': 'Realm',
'function': lambda item, req: item.realm,
},
'retry_interval': {
'description': 'Number of basic interval lengths between checks when retrying after a soft error',
'function': lambda item, req: item.retry_interval,
'datatype': float,
},
'scheduled_downtime_depth': {
'description': 'The number of downtimes this host is currently in',
'function': lambda item, req: item.scheduled_downtime_depth,
'datatype': int,
},
'services': {
'description': 'A list of all services of the host',
'function': lambda item, req: [x.get_name() for x in item.services],
'datatype': list,
},
'services_with_info': {
'description': 'A list of all services including detailed information about each service',
'function': lambda item, req: item.services_with_info, # REPAIRME
'datatype': list,
# Dummy Service|0|1|Please remove this service later,Deppen Service|2|1|depp
},
'services_with_state': {
'description': 'A list of all services of the host together with state and has_been_checked',
'function': lambda item, req: [join_with_separators(req, x.get_name(), x.state_id, x.has_been_checked) for x in item.services],
'datatype': list,
},
'source_problems': {
'description': 'The name of the source problems (host or service)',
'function': lambda item, req: [get_livestatus_full_name(i, req) for i in item.source_problems], # REPAIRME MAYBE (separators in python and csv)
'datatype': list,
},
'state': {
'description': 'The current state of the host (0: up, 1: down, 2: unreachable)',
'function': lambda item, req: item.state_id,
#'function': i_am_state,
'datatype': int,
},
'state_type': {
'description': 'Type of the current state (0: soft, 1: hard)',
'function': lambda item, req: item.state_type_id,
'datatype': int,
},
'statusmap_image': {
'description': 'The name of in image file for the status map',
'function': lambda item, req: item.statusmap_image,
},
'tags': {
'description': 'The list of Host Tags',
'function': lambda item, req: [join_with_separators(req, x) for x in item.tags],
'datatype': list,
},
'total_services': {
'description': 'The total number of services of the host',
'function': lambda item, req: "", # REPAIRME
'datatype': int,
},
'worst_service_hard_state': {
'description': 'The worst hard state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
'function': lambda item, req: reduce(worst_service_state, (x.state_id for x in item.services if x.state_type_id == 1), 0),
'datatype': int,
},
'worst_service_state': {
'description': 'The worst soft state of all of the host\'s services (OK <= WARN <= UNKNOWN <= CRIT)',
'function': lambda item, req: reduce(worst_service_state, (x.state_id for x in item.services), 0),
'datatype': int,
},
'x_3d': {
'description': '3D-Coordinates: X',
'function': lambda item, req: "", # REPAIRME
'datatype': float,
},
'y_3d': {
'description': '3D-Coordinates: Y',
'function': lambda item, req: "", # REPAIRME
'datatype': float,
},
'z_3d': {
'description': '3D-Coordinates: Z',
'function': lambda item, req: "", # REPAIRME
'datatype': float,
},
},
'Service': {
'accept_passive_checks': {
'description': 'Whether the service accepts passive checks (0/1)',
'function': lambda item, req: item.passive_checks_enabled,
'datatype': bool,
},
'acknowledged': {
'description': 'Whether the current service problem has been acknowledged (0/1)',
'function': lambda item, req: item.problem_has_been_acknowledged,
'datatype': bool,
},
'acknowledgement_type': {
'description': 'The type of the acknownledgement (0: none, 1: normal, 2: sticky)',
'function': lambda item, req: item.acknowledgement_type,
'datatype': int,
},
'action_url': {
'description': 'An optional URL for actions or custom information about the service',
'function': lambda item, req: item.action_url,
},
'action_url_expanded': {
'description': 'The action_url with (the most important) macros expanded',
'function': lambda item, req: MacroResolver().resolve_simple_macros_in_string(item.action_url, item.get_data_for_checks()),
},
'active_checks_enabled': {
'description': 'Whether active checks are enabled for the service (0/1)',
'function': lambda item, req: item.active_checks_enabled,
'datatype': bool,
},
'business_impact': {
'description': 'The importance we gave to this service between the minimum 0 and the maximum 5',
'function': lambda item, req: item.business_impact,
'datatype': int,
},
'check_command': {
'description': 'Nagios command used for active checks',
'function': lambda item, req: item.check_command.get_name(),
},
'check_interval': {
'description': 'Number of basic interval lengths between two scheduled checks of the service',
'function': lambda item, req: item.check_interval,
'datatype': float,
},
'check_options': {
'description': 'The current check option, forced, normal, freshness... (0/1)',
'function': lambda item, req: "", # REPAIRME
'datatype': int,
},
'check_period': {
'description': 'The name of the check period of the service. It this is empty, the service is always checked.',
'function': lambda item, req: item.check_period.get_name(),
},
'check_type': {
'description': 'The type of the last check (0: active, 1: passive)',
'function': lambda item, req: int(item.check_type),
'datatype': int,
},
'checks_enabled': {
'description': 'Whether active checks are enabled for the service (0/1)',
'function': lambda item, req: item.active_checks_enabled,
'datatype': bool,
},
'child_dependencies': {
'description': 'List of the host/service that depend on this service (logical, network or business one).',
'function': lambda item, req: from_svc_hst_distinct_lists(item.child_dependencies),
'datatype': list,
},
'comments': {
'description': 'A list of all comment ids of the service',
'function': lambda item, req: [x.id for x in item.comments],
'datatype': list,
},
'comments_with_info': {
'description': 'A list of the ids of all comments of this service with id, author and comment',
'function': lambda item, req: [join_with_separators(req, str(x.id), x.author, x.comment) for x in item.comments], # REPAIRME MAYBE
'datatype': list,
},
'contacts': {
'description': 'A list of all contacts of the service, either direct or via a contact group',
'function': lambda item, req: [x.contact_name for x in item.contacts], # CONTROLME c1 is in group cg1, c2 is in no group. svc has cg1,c2. only c2 is shown here
'datatype': list,
},
'contact_groups': {
'description': 'A list of all contact groups this service is in',
'function': lambda item, req: item.contact_groups,
'datatype': list,
},
'criticity': {
'description': 'The importance we gave to this service between the minimum 0 and the maximum 5',
'function': lambda item, req: item.business_impact,
'datatype': int,
},
'current_attempt': {
'description': 'The number of the current check attempt',
'function': lambda item, req: item.attempt,
'datatype': int,
},
'current_notification_number': {
'description': 'The number of the current notification',
'function': lambda item, req: item.current_notification_number,
'datatype': int,
},
'custom_variables': {
'description': 'A dictionary of the custom variables',
'function': lambda item, req: [join_with_separators(req, k[1:], v) for k, v in item.customs.iteritems()],
'datatype': list,
},
'custom_variable_names': {
'description': 'A list of the names of all custom variables of the service',
'function': lambda item, req: get_customs_keys(item.customs),
'datatype': list,
},
'custom_variable_values': {
'description': 'A list of the values of all custom variable of the service',
'function': lambda item, req: get_customs_values(item.customs),
'datatype': list,
},
'description': {
'description': 'Description of the service (also used as key)',
'function': lambda item, req: item.service_description,
},
'display_name': {
'description': 'An optional display name (not used by Nagios standard web pages)',
'function': lambda item, req: item.display_name,
},
'downtimes': {
'description': 'A list of all downtime ids of the service',
'function': lambda item, req: [x.id for x in item.downtimes],
'datatype': list,
},
'downtimes_with_info': {
'description': 'A list of all downtimes of the service with id, author and comment',
'function': lambda item, req: [join_with_separators(req, str(x.id), x.author, x.comment) for x in item.downtimes], # REPAIRME MAYBE
'datatype': list,
},
'event_handler': {
'description': 'Nagios command used as event handler',
'function': lambda item, req: item.event_handler.get_name(),
},
'event_handler_enabled': {
'description': 'Whether and event handler is activated for the service (0/1)',
'function': lambda item, req: item.event_handler_enabled,
'datatype': bool,
},
'execution_time': {
'description': 'Time the host check needed for execution',
'function': lambda item, req: item.execution_time,
'datatype': float,
},
'first_notification_delay': {
'description': 'Delay before the first notification',
'function': lambda item, req: item.first_notification_delay,
'datatype': float,
},
'flap_detection_enabled': {
'description': 'Whether flap detection is enabled for the service (0/1)',
'function': lambda item, req: item.flap_detection_enabled,
'datatype': bool,
},
'got_business_rule': {
'description': 'Whether the service state is an business rule based host or not (0/1)',
'function': lambda item, req: item.got_business_rule,
'datatype': bool,
},
'groups': {
'description': 'A list of all service groups the service is in',
'function': lambda item, req: [x.get_name() for x in item.servicegroups],
'datatype': list,
},
'has_been_checked': {
'description': 'Whether the service already has been checked (0/1)',
'function': lambda item, req: item.has_been_checked,
'datatype': int,
},
'high_flap_threshold': {
'description': 'High threshold of flap detection',
'function': lambda item, req: item.high_flap_threshold,
'datatype': float,
},
'host_accept_passive_checks': {
'description': 'Whether passive host checks are accepted (0/1)',
},
'host_acknowledged': {
'description': 'Whether the current host problem has been acknowledged (0/1)',
},
'host_acknowledgement_type': {
'description': 'Type of acknowledgement (0: none, 1: normal, 2: stick)',
},
'host_action_url': {
'description': 'An optional URL to custom actions or information about this host',
},
'host_action_url_expanded': {
'description': 'The same as action_url, but with the most important macros expanded',
},
'host_active_checks_enabled': {
'description': 'Whether active checks are enabled for the host (0/1)',
},
'host_address': {
'description': 'IP address',
},
'host_alias': {
'description': 'An alias name for the host',
},
'host_check_command': {
'description': 'Nagios command for active host check of this host',
},
'host_check_flapping_recovery_notification': {
'description': 'Whether to check to send a recovery notification when flapping stops (0/1)',
},
'host_check_freshness': {
'description': 'Whether freshness checks are activated (0/1)',
},
'host_check_interval': {
'description': 'Number of basic interval lengths between two scheduled checks of the host',
},
'host_check_options': {
'description': 'The current check option, forced, normal, freshness... (0-2)',
},
'host_check_period': {
'description': 'Time period in which this host will be checked. If empty then the host will always be checked.',
},
'host_check_type': {
'description': 'Type of check (0: active, 1: passive)',
},
'host_checks_enabled': {
'description': 'Whether checks of the host are enabled (0/1)',
},
'host_childs': {
'description': 'A list of all direct childs of the host',
},
'host_comments': {
'description': 'A list of the ids of all comments of this host',
},
'host_comments_with_info': {
'description': 'A list of the ids of all comments of this host',
},
'host_contacts': {
'description': 'A list of all contacts of this host, either direct or via a contact group',
},
'host_contact_groups': {
'description': 'A list of all contact groups this host is in',
},
'host_current_attempt': {
'description': 'Number of the current check attempts',
},
'host_current_notification_number': {
'description': 'Number of the current notification',
},
'host_custom_variables': {
'description': 'A dictionary of the custom variables',
},
'host_custom_variable_names': {
'description': 'A list of the names of all custom variables',
},
'host_custom_variable_values': {
'description': 'A list of the values of the custom variables',
},
'host_display_name': {
'description': 'Optional display name of the host - not used by Nagios\' web interface',
},
'host_downtimes': {
'description': 'A list of the ids of all scheduled downtimes of this host',
},
'host_downtimes_with_info': {
'description': 'A list of the all scheduled downtimes of the host with id, author and comment',