-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnagext.py
1315 lines (1148 loc) · 60.5 KB
/
nagext.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
# Copyright 2010 Alexander Duryagin
#
# This file is part of NagExt.
#
# NagExt is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# NagExt 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NagExt. If not, see <http://www.gnu.org/licenses/>.
#
"""
This module provides python interface to Nagios external commands
"""
import os
import stat
from time import time
class ExecError(Exception):
"""
Errors while executing command (writing external command to command file)
"""
pass
class NagExt(object):
"""
Deal with nagios command file for executing external commands.
Writes commands to Nagios command_file in following format:
[time] command_id;command_arguments
"""
def __init__(self, command_file):
self.command_file = command_file
self._cmd_f = None
self.open()
def __del__(self):
self.close()
def open(self):
"""Open Nagios command file
Raises:
ExecError: if the file 'command_file' doesn't exist, can't be open
or is not a pipe (fifo)
"""
try:
st = os.stat(self.command_file)
if not stat.S_ISFIFO(st.st_mode):
raise IOError('The command file "%s" is not a pipe' %
self.command_file)
self._cmd_f = open(self.command_file, 'w')
except (OSError, IOError) as e:
raise ExecError(str(e))
def close(self):
"""
Close Nagios command file
"""
self._cmd_f.close()
def run(self, cmd, *args):
"""
Run Nagios external command with given arguments,
converting bool to int.
"""
def normalize_args(a):
if isinstance(a, bool):
a = int(a)
return str(a)
try:
str_args = ';'.join([normalize_args(a) for a in args])
self._cmd_f.write("[%lu] %s;%s\n" % (time(), cmd, str_args))
self._cmd_f.flush()
except Exception as e:
raise ExecError(str(e))
# next follow automatically generated methods from nagios developer documentation
# for external commands
def change_contact_host_notification_timeperiod(self, contact_name, notification_timeperiod):
"""
Changes the host notification timeperiod for a particular contact to what is
specified by the "notification_timeperiod" option. The
"notification_timeperiod" option should be the short name of the timeperiod that
is to be used as the contact's host notification timeperiod. The timeperiod
must have been configured in Nagios before it was last (re)started.
"""
self.run('CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD', contact_name, notification_timeperiod)
def change_contact_modattr(self, contact_name, value):
"""
This command changes the modified attributes value for the specified contact.
Modified attributes values are used by Nagios to determine which object
properties should be retained across program restarts. Thus, modifying the
value of the attributes can affect data retention. This is an advanced option
and should only be used by people who are intimately familiar with the data
retention logic in Nagios.
"""
self.run('CHANGE_CONTACT_MODATTR', contact_name, value)
def change_contact_modhattr(self, contact_name, value):
"""
This command changes the modified host attributes value for the specified
contact. Modified attributes values are used by Nagios to determine which
object properties should be retained across program restarts. Thus, modifying
the value of the attributes can affect data retention. This is an advanced
option and should only be used by people who are intimately familiar with the
data retention logic in Nagios.
"""
self.run('CHANGE_CONTACT_MODHATTR', contact_name, value)
def change_contact_modsattr(self, contact_name, value):
"""
This command changes the modified service attributes value for the specified
contact. Modified attributes values are used by Nagios to determine which
object properties should be retained across program restarts. Thus, modifying
the value of the attributes can affect data retention. This is an advanced
option and should only be used by people who are intimately familiar with the
data retention logic in Nagios.
"""
self.run('CHANGE_CONTACT_MODSATTR', contact_name, value)
def change_contact_svc_notification_timeperiod(self, contact_name, notification_timeperiod):
"""
Changes the service notification timeperiod for a particular contact to what is
specified by the "notification_timeperiod" option. The
"notification_timeperiod" option should be the short name of the timeperiod that
is to be used as the contact's service notification timeperiod. The timeperiod
must have been configured in Nagios before it was last (re)started.
"""
self.run('CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD', contact_name, notification_timeperiod)
def change_custom_contact_var(self, contact_name, varname, varvalue):
"""
Changes the value of a custom contact variable.
"""
self.run('CHANGE_CUSTOM_CONTACT_VAR', contact_name, varname, varvalue)
def change_custom_host_var(self, host_name, varname, varvalue):
"""
Changes the value of a custom host variable.
"""
self.run('CHANGE_CUSTOM_HOST_VAR', host_name, varname, varvalue)
def change_custom_svc_var(self, host_name, service_description, varname, varvalue):
"""
Changes the value of a custom service variable.
"""
self.run('CHANGE_CUSTOM_SVC_VAR', host_name, service_description, varname, varvalue)
def change_global_host_event_handler(self, event_handler_command):
"""
Changes the global host event handler command to be that specified by the
"event_handler_command" option. The "event_handler_command" option specifies
the short name of the command that should be used as the new host event handler.
The command must have been configured in Nagios before it was last (re)started.
"""
self.run('CHANGE_GLOBAL_HOST_EVENT_HANDLER', event_handler_command)
def change_global_svc_event_handler(self, event_handler_command):
"""
Changes the global service event handler command to be that specified by the
"event_handler_command" option. The "event_handler_command" option specifies
the short name of the command that should be used as the new service event
handler. The command must have been configured in Nagios before it was last
(re)started.
"""
self.run('CHANGE_GLOBAL_SVC_EVENT_HANDLER', event_handler_command)
def change_host_check_command(self, host_name, check_command):
"""
Changes the check command for a particular host to be that specified by the
"check_command" option. The "check_command" option specifies the short name of
the command that should be used as the new host check command. The command must
have been configured in Nagios before it was last (re)started.
"""
self.run('CHANGE_HOST_CHECK_COMMAND', host_name, check_command)
def change_host_check_timeperiod(self, host_name, timeperiod):
"""
Changes the valid check period for the specified host.
"""
self.run('CHANGE_HOST_CHECK_TIMEPERIOD', host_name, timeperiod)
def change_host_check_timeperiod(self, host_name, check_timeperod):
"""
Changes the check timeperiod for a particular host to what is specified by the
"check_timeperiod" option. The "check_timeperiod" option should be the short
name of the timeperod that is to be used as the host check timeperiod. The
timeperiod must have been configured in Nagios before it was last (re)started.
"""
self.run('CHANGE_HOST_CHECK_TIMEPERIOD', host_name, check_timeperod)
def change_host_event_handler(self, host_name, event_handler_command):
"""
Changes the event handler command for a particular host to be that specified by
the "event_handler_command" option. The "event_handler_command" option
specifies the short name of the command that should be used as the new host
event handler. The command must have been configured in Nagios before it was
last (re)started.
"""
self.run('CHANGE_HOST_EVENT_HANDLER', host_name, event_handler_command)
def change_host_modattr(self, host_name, value):
"""
This command changes the modified attributes value for the specified host.
Modified attributes values are used by Nagios to determine which object
properties should be retained across program restarts. Thus, modifying the
value of the attributes can affect data retention. This is an advanced option
and should only be used by people who are intimately familiar with the data
retention logic in Nagios.
"""
self.run('CHANGE_HOST_MODATTR', host_name, value)
def change_max_host_check_attempts(self, host_name, check_attempts):
"""
Changes the maximum number of check attempts (retries) for a particular host.
"""
self.run('CHANGE_MAX_HOST_CHECK_ATTEMPTS', host_name, check_attempts)
def change_max_svc_check_attempts(self, host_name, service_description, check_attempts):
"""
Changes the maximum number of check attempts (retries) for a particular
service.
"""
self.run('CHANGE_MAX_SVC_CHECK_ATTEMPTS', host_name, service_description, check_attempts)
def change_normal_host_check_interval(self, host_name, check_interval):
"""
Changes the normal (regularly scheduled) check interval for a particular host.
"""
self.run('CHANGE_NORMAL_HOST_CHECK_INTERVAL', host_name, check_interval)
def change_normal_svc_check_interval(self, host_name, service_description, check_interval):
"""
Changes the normal (regularly scheduled) check interval for a particular
service
"""
self.run('CHANGE_NORMAL_SVC_CHECK_INTERVAL', host_name, service_description, check_interval)
def change_retry_host_check_interval(self, host_name, service_description, check_interval):
"""
Changes the retry check interval for a particular host.
"""
self.run('CHANGE_RETRY_HOST_CHECK_INTERVAL', host_name, service_description, check_interval)
def change_retry_svc_check_interval(self, host_name, service_description, check_interval):
"""
Changes the retry check interval for a particular service.
"""
self.run('CHANGE_RETRY_SVC_CHECK_INTERVAL', host_name, service_description, check_interval)
def change_svc_check_command(self, host_name, service_description, check_command):
"""
Changes the check command for a particular service to be that specified by the
"check_command" option. The "check_command" option specifies the short name of
the command that should be used as the new service check command. The command
must have been configured in Nagios before it was last (re)started.
"""
self.run('CHANGE_SVC_CHECK_COMMAND', host_name, service_description, check_command)
def change_svc_check_timeperiod(self, host_name, service_description, check_timeperiod):
"""
Changes the check timeperiod for a particular service to what is specified by
the "check_timeperiod" option. The "check_timeperiod" option should be the
short name of the timeperod that is to be used as the service check timeperiod.
The timeperiod must have been configured in Nagios before it was last
(re)started.
"""
self.run('CHANGE_SVC_CHECK_TIMEPERIOD', host_name, service_description, check_timeperiod)
def change_svc_event_handler(self, host_name, service_description, event_handler_command):
"""
Changes the event handler command for a particular service to be that specified
by the "event_handler_command" option. The "event_handler_command" option
specifies the short name of the command that should be used as the new service
event handler. The command must have been configured in Nagios before it was
last (re)started.
"""
self.run('CHANGE_SVC_EVENT_HANDLER', host_name, service_description, event_handler_command)
def change_svc_modattr(self, host_name, service_description, value):
"""
This command changes the modified attributes value for the specified service.
Modified attributes values are used by Nagios to determine which object
properties should be retained across program restarts. Thus, modifying the
value of the attributes can affect data retention. This is an advanced option
and should only be used by people who are intimately familiar with the data
retention logic in Nagios.
"""
self.run('CHANGE_SVC_MODATTR', host_name, service_description, value)
def change_svc_notification_timeperiod(self, host_name, service_description, notification_timeperiod):
"""
Changes the notification timeperiod for a particular service to what is
specified by the "notification_timeperiod" option. The
"notification_timeperiod" option should be the short name of the timeperiod that
is to be used as the service notification timeperiod. The timeperiod must have
been configured in Nagios before it was last (re)started.
"""
self.run('CHANGE_SVC_NOTIFICATION_TIMEPERIOD', host_name, service_description, notification_timeperiod)
def delay_host_notification(self, host_name, notification_time):
"""
Delays the next notification for a parciular service until "notification_time".
The "notification_time" argument is specified in time_t format (seconds since
the UNIX epoch). Note that this will only have an affect if the service stays
in the same problem state that it is currently in. If the service changes to
another state, a new notification may go out before the time you specify in the
"notification_time" argument.
"""
self.run('DELAY_HOST_NOTIFICATION', host_name, notification_time)
def delay_svc_notification(self, host_name, service_description, notification_time):
"""
Delays the next notification for a parciular service until "notification_time".
The "notification_time" argument is specified in time_t format (seconds since
the UNIX epoch). Note that this will only have an affect if the service stays
in the same problem state that it is currently in. If the service changes to
another state, a new notification may go out before the time you specify in the
"notification_time" argument.
"""
self.run('DELAY_SVC_NOTIFICATION', host_name, service_description, notification_time)
def del_all_host_comments(self, host_name):
"""
Deletes all comments assocated with a particular host.
"""
self.run('DEL_ALL_HOST_COMMENTS', host_name)
def del_all_svc_comments(self, host_name, service_description):
"""
Deletes all comments associated with a particular service.
"""
self.run('DEL_ALL_SVC_COMMENTS', host_name, service_description)
def del_host_comment(self, comment_id):
"""
Deletes a host comment. The id number of the comment that is to be deleted must
be specified.
"""
self.run('DEL_HOST_COMMENT', comment_id)
def del_host_downtime(self, downtime_id):
"""
Deletes the host downtime entry that has an ID number matching the "downtime_id"
argument. If the downtime is currently in effect, the host will come out of
scheduled downtime (as long as there are no other overlapping active downtime
entries).
"""
self.run('DEL_HOST_DOWNTIME', downtime_id)
def del_svc_comment(self, comment_id):
"""
Deletes a service comment. The id number of the comment that is to be deleted
must be specified.
"""
self.run('DEL_SVC_COMMENT', comment_id)
def del_svc_downtime(self, downtime_id):
"""
Deletes the service downtime entry that has an ID number matching the
"downtime_id" argument. If the downtime is currently in effect, the service
will come out of scheduled downtime (as long as there are no other overlapping
active downtime entries).
"""
self.run('DEL_SVC_DOWNTIME', downtime_id)
def disable_all_notifications_beyond_host(self, host_name):
"""
Disables notifications for all hosts and services "beyond" (e.g. on all child
hosts of) the specified host. The current notification setting for the
specified host is not affected.
"""
self.run('DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST', host_name)
def disable_contactgroup_host_notifications(self, contactgroup_name):
"""
Disables host notifications for all contacts in a particular contactgroup.
"""
self.run('DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS', contactgroup_name)
def disable_contactgroup_svc_notifications(self, contactgroup_name):
"""
Disables service notifications for all contacts in a particular contactgroup.
"""
self.run('DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS', contactgroup_name)
def disable_contact_host_notifications(self, contact_name):
"""
Disables host notifications for a particular contact.
"""
self.run('DISABLE_CONTACT_HOST_NOTIFICATIONS', contact_name)
def disable_contact_svc_notifications(self, contact_name):
"""
Disables service notifications for a particular contact.
"""
self.run('DISABLE_CONTACT_SVC_NOTIFICATIONS', contact_name)
def disable_event_handlers(self, ):
"""
Disables host and service event handlers on a program-wide basis.
"""
self.run('DISABLE_EVENT_HANDLERS', )
def disable_failure_prediction(self, ):
"""
Disables failure prediction on a program-wide basis. This feature is not
currently implemented in Nagios.
"""
self.run('DISABLE_FAILURE_PREDICTION', )
def disable_flap_detection(self, ):
"""
Disables host and service flap detection on a program-wide basis.
"""
self.run('DISABLE_FLAP_DETECTION', )
def disable_hostgroup_host_checks(self, hostgroup_name):
"""
Disables active checks for all hosts in a particular hostgroup.
"""
self.run('DISABLE_HOSTGROUP_HOST_CHECKS', hostgroup_name)
def disable_hostgroup_host_notifications(self, hostgroup_name):
"""
Disables notifications for all hosts in a particular hostgroup. This does not
disable notifications for the services associated with the hosts in the
hostgroup - see the DISABLE_HOSTGROUP_SVC_NOTIFICATIONS command for that.
"""
self.run('DISABLE_HOSTGROUP_HOST_NOTIFICATIONS', hostgroup_name)
def disable_hostgroup_passive_host_checks(self, hostgroup_name):
"""
Disables passive checks for all hosts in a particular hostgroup.
"""
self.run('DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS', hostgroup_name)
def disable_hostgroup_passive_svc_checks(self, hostgroup_name):
"""
Disables passive checks for all services associated with hosts in a particular
hostgroup.
"""
self.run('DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS', hostgroup_name)
def disable_hostgroup_svc_checks(self, hostgroup_name):
"""
Disables active checks for all services associated with hosts in a particular
hostgroup.
"""
self.run('DISABLE_HOSTGROUP_SVC_CHECKS', hostgroup_name)
def disable_hostgroup_svc_notifications(self, hostgroup_name):
"""
Disables notifications for all services associated with hosts in a particular
hostgroup. This does not disable notifications for the hosts in the hostgroup -
see the DISABLE_HOSTGROUP_HOST_NOTIFICATIONS command for that.
"""
self.run('DISABLE_HOSTGROUP_SVC_NOTIFICATIONS', hostgroup_name)
def disable_host_and_child_notifications(self, host_name):
"""
Disables notifications for the specified host, as well as all hosts "beyond"
(e.g. on all child hosts of) the specified host.
"""
self.run('DISABLE_HOST_AND_CHILD_NOTIFICATIONS', host_name)
def disable_host_check(self, host_name):
"""
Disables (regularly scheduled and on-demand) active checks of the specified
host.
"""
self.run('DISABLE_HOST_CHECK', host_name)
def disable_host_event_handler(self, host_name):
"""
Disables the event handler for the specified host.
"""
self.run('DISABLE_HOST_EVENT_HANDLER', host_name)
def disable_host_flap_detection(self, host_name):
"""
Disables flap detection for the specified host.
"""
self.run('DISABLE_HOST_FLAP_DETECTION', host_name)
def disable_host_freshness_checks(self, ):
"""
Disables freshness checks of all hosts on a program-wide basis.
"""
self.run('DISABLE_HOST_FRESHNESS_CHECKS', )
def disable_host_notifications(self, host_name):
"""
Disables notifications for a particular host.
"""
self.run('DISABLE_HOST_NOTIFICATIONS', host_name)
def disable_host_svc_checks(self, host_name):
"""
Enables active checks of all services on the specified host.
"""
self.run('DISABLE_HOST_SVC_CHECKS', host_name)
def disable_host_svc_notifications(self, host_name):
"""
Disables notifications for all services on the specified host.
"""
self.run('DISABLE_HOST_SVC_NOTIFICATIONS', host_name)
def disable_notifications(self, ):
"""
Disables host and service notifications on a program-wide basis.
"""
self.run('DISABLE_NOTIFICATIONS', )
def disable_passive_host_checks(self, host_name):
"""
Disables acceptance and processing of passive host checks for the specified
host.
"""
self.run('DISABLE_PASSIVE_HOST_CHECKS', host_name)
def disable_passive_svc_checks(self, host_name, service_description):
"""
Disables passive checks for the specified service.
"""
self.run('DISABLE_PASSIVE_SVC_CHECKS', host_name, service_description)
def disable_performance_data(self, ):
"""
Disables the processing of host and service performance data on a program-wide
basis.
"""
self.run('DISABLE_PERFORMANCE_DATA', )
def disable_servicegroup_host_checks(self, servicegroup_name):
"""
Disables active checks for all hosts that have services that are members of a
particular hostgroup.
"""
self.run('DISABLE_SERVICEGROUP_HOST_CHECKS', servicegroup_name)
def disable_servicegroup_host_notifications(self, servicegroup_name):
"""
Disables notifications for all hosts that have services that are members of a
particular servicegroup.
"""
self.run('DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS', servicegroup_name)
def disable_servicegroup_passive_host_checks(self, servicegroup_name):
"""
Disables the acceptance and processing of passive checks for all hosts that have
services that are members of a particular service group.
"""
self.run('DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS', servicegroup_name)
def disable_servicegroup_passive_svc_checks(self, servicegroup_name):
"""
Disables the acceptance and processing of passive checks for all services in a
particular servicegroup.
"""
self.run('DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS', servicegroup_name)
def disable_servicegroup_svc_checks(self, servicegroup_name):
"""
Disables active checks for all services in a particular servicegroup.
"""
self.run('DISABLE_SERVICEGROUP_SVC_CHECKS', servicegroup_name)
def disable_servicegroup_svc_notifications(self, servicegroup_name):
"""
Disables notifications for all services that are members of a particular
servicegroup.
"""
self.run('DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS', servicegroup_name)
def disable_service_flap_detection(self, host_name, service_description):
"""
Disables flap detection for the specified service.
"""
self.run('DISABLE_SERVICE_FLAP_DETECTION', host_name, service_description)
def disable_service_freshness_checks(self, ):
"""
Disables freshness checks of all services on a program-wide basis.
"""
self.run('DISABLE_SERVICE_FRESHNESS_CHECKS', )
def disable_svc_check(self, host_name, service_description):
"""
Disables active checks for a particular service.
"""
self.run('DISABLE_SVC_CHECK', host_name, service_description)
def disable_svc_event_handler(self, host_name, service_description):
"""
Disables the event handler for the specified service.
"""
self.run('DISABLE_SVC_EVENT_HANDLER', host_name, service_description)
def disable_svc_flap_detection(self, host_name, service_description):
"""
Disables flap detection for the specified service.
"""
self.run('DISABLE_SVC_FLAP_DETECTION', host_name, service_description)
def disable_svc_notifications(self, host_name, service_description):
"""
Disables notifications for a particular service.
"""
self.run('DISABLE_SVC_NOTIFICATIONS', host_name, service_description)
def enable_all_notifications_beyond_host(self, host_name):
"""
Enables notifications for all hosts and services "beyond" (e.g. on all child
hosts of) the specified host. The current notification setting for the
specified host is not affected. Notifications will only be sent out for these
hosts and services if notifications are also enabled on a program-wide basis.
"""
self.run('ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST', host_name)
def enable_contactgroup_host_notifications(self, contactgroup_name):
"""
Enables host notifications for all contacts in a particular contactgroup.
"""
self.run('ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS', contactgroup_name)
def enable_contactgroup_svc_notifications(self, contactgroup_name):
"""
Enables service notifications for all contacts in a particular contactgroup.
"""
self.run('ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS', contactgroup_name)
def enable_contact_host_notifications(self, contact_name):
"""
Enables host notifications for a particular contact.
"""
self.run('ENABLE_CONTACT_HOST_NOTIFICATIONS', contact_name)
def enable_contact_svc_notifications(self, contact_name):
"""
Disables service notifications for a particular contact.
"""
self.run('ENABLE_CONTACT_SVC_NOTIFICATIONS', contact_name)
def enable_event_handlers(self, ):
"""
Enables host and service event handlers on a program-wide basis.
"""
self.run('ENABLE_EVENT_HANDLERS', )
def enable_failure_prediction(self, ):
"""
Enables failure prediction on a program-wide basis. This feature is not
currently implemented in Nagios.
"""
self.run('ENABLE_FAILURE_PREDICTION', )
def enable_flap_detection(self, ):
"""
Enables host and service flap detection on a program-wide basis.
"""
self.run('ENABLE_FLAP_DETECTION', )
def enable_hostgroup_host_checks(self, hostgroup_name):
"""
Enables active checks for all hosts in a particular hostgroup.
"""
self.run('ENABLE_HOSTGROUP_HOST_CHECKS', hostgroup_name)
def enable_hostgroup_host_notifications(self, hostgroup_name):
"""
Enables notifications for all hosts in a particular hostgroup. This does not
enable notifications for the services associated with the hosts in the hostgroup
- see the ENABLE_HOSTGROUP_SVC_NOTIFICATIONS command for that. In order for
notifications to be sent out for these hosts, notifications must be enabled on a
program-wide basis as well.
"""
self.run('ENABLE_HOSTGROUP_HOST_NOTIFICATIONS', hostgroup_name)
def enable_hostgroup_passive_host_checks(self, hostgroup_name):
"""
Enables passive checks for all hosts in a particular hostgroup.
"""
self.run('ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS', hostgroup_name)
def enable_hostgroup_passive_svc_checks(self, hostgroup_name):
"""
Enables passive checks for all services associated with hosts in a particular
hostgroup.
"""
self.run('ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS', hostgroup_name)
def enable_hostgroup_svc_checks(self, hostgroup_name):
"""
Enables active checks for all services associated with hosts in a particular
hostgroup.
"""
self.run('ENABLE_HOSTGROUP_SVC_CHECKS', hostgroup_name)
def enable_hostgroup_svc_notifications(self, hostgroup_name):
"""
Enables notifications for all services that are associated with hosts in a
particular hostgroup. This does not enable notifications for the hosts in the
hostgroup - see the ENABLE_HOSTGROUP_HOST_NOTIFICATIONS command for that. In
order for notifications to be sent out for these services, notifications must be
enabled on a program-wide basis as well.
"""
self.run('ENABLE_HOSTGROUP_SVC_NOTIFICATIONS', hostgroup_name)
def enable_host_and_child_notifications(self, host_name):
"""
Enables notifications for the specified host, as well as all hosts "beyond"
(e.g. on all child hosts of) the specified host. Notifications will only be
sent out for these hosts if notifications are also enabled on a program-wide
basis.
"""
self.run('ENABLE_HOST_AND_CHILD_NOTIFICATIONS', host_name)
def enable_host_check(self, host_name):
"""
Enables (regularly scheduled and on-demand) active checks of the specified
host.
"""
self.run('ENABLE_HOST_CHECK', host_name)
def enable_host_event_handler(self, host_name):
"""
Enables the event handler for the specified host.
"""
self.run('ENABLE_HOST_EVENT_HANDLER', host_name)
def enable_host_flap_detection(self, host_name):
"""
Enables flap detection for the specified host. In order for the flap detection
algorithms to be run for the host, flap detection must be enabled on a
program-wide basis as well.
"""
self.run('ENABLE_HOST_FLAP_DETECTION', host_name)
def enable_host_freshness_checks(self, ):
"""
Enables freshness checks of all hosts on a program-wide basis. Individual hosts
that have freshness checks disabled will not be checked for freshness.
"""
self.run('ENABLE_HOST_FRESHNESS_CHECKS', )
def enable_host_notifications(self, host_name):
"""
Enables notifications for a particular host. Notifications will be sent out for
the host only if notifications are enabled on a program-wide basis as well.
"""
self.run('ENABLE_HOST_NOTIFICATIONS', host_name)
def enable_host_svc_checks(self, host_name):
"""
Enables active checks of all services on the specified host.
"""
self.run('ENABLE_HOST_SVC_CHECKS', host_name)
def enable_host_svc_notifications(self, host_name):
"""
Enables notifications for all services on the specified host. Note that
notifications will not be sent out if notifications are disabled on a
program-wide basis.
"""
self.run('ENABLE_HOST_SVC_NOTIFICATIONS', host_name)
def enable_notifications(self, ):
"""
Enables host and service notifications on a program-wide basis.
"""
self.run('ENABLE_NOTIFICATIONS', )
def enable_passive_host_checks(self, host_name):
"""
Enables acceptance and processing of passive host checks for the specified
host.
"""
self.run('ENABLE_PASSIVE_HOST_CHECKS', host_name)
def enable_passive_svc_checks(self, host_name, service_description):
"""
Enables passive checks for the specified service.
"""
self.run('ENABLE_PASSIVE_SVC_CHECKS', host_name, service_description)
def enable_performance_data(self, ):
"""
Enables the processing of host and service performance data on a program-wide
basis.
"""
self.run('ENABLE_PERFORMANCE_DATA', )
def enable_servicegroup_host_checks(self, servicegroup_name):
"""
Enables active checks for all hosts that have services that are members of a
particular hostgroup.
"""
self.run('ENABLE_SERVICEGROUP_HOST_CHECKS', servicegroup_name)
def enable_servicegroup_host_notifications(self, servicegroup_name):
"""
Enables notifications for all hosts that have services that are members of a
particular servicegroup. In order for notifications to be sent out for these
hosts, notifications must also be enabled on a program-wide basis.
"""
self.run('ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS', servicegroup_name)
def enable_servicegroup_passive_host_checks(self, servicegroup_name):
"""
Enables the acceptance and processing of passive checks for all hosts that have
services that are members of a particular service group.
"""
self.run('ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS', servicegroup_name)
def enable_servicegroup_passive_svc_checks(self, servicegroup_name):
"""
Enables the acceptance and processing of passive checks for all services in a
particular servicegroup.
"""
self.run('ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS', servicegroup_name)
def enable_servicegroup_svc_checks(self, servicegroup_name):
"""
Enables active checks for all services in a particular servicegroup.
"""
self.run('ENABLE_SERVICEGROUP_SVC_CHECKS', servicegroup_name)
def enable_servicegroup_svc_notifications(self, servicegroup_name):
"""
Enables notifications for all services that are members of a particular
servicegroup. In order for notifications to be sent out for these services,
notifications must also be enabled on a program-wide basis.
"""
self.run('ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS', servicegroup_name)
def enable_service_freshness_checks(self, ):
"""
Enables freshness checks of all services on a program-wide basis. Individual
services that have freshness checks disabled will not be checked for freshness.
"""
self.run('ENABLE_SERVICE_FRESHNESS_CHECKS', )
def enable_svc_check(self, host_name, service_description):
"""
Enables active checks for a particular service.
"""
self.run('ENABLE_SVC_CHECK', host_name, service_description)
def enable_svc_event_handler(self, host_name, service_description):
"""
Enables the event handler for the specified service.
"""
self.run('ENABLE_SVC_EVENT_HANDLER', host_name, service_description)
def enable_svc_flap_detection(self, host_name, service_description):
"""
Enables flap detection for the specified service. In order for the flap
detection algorithms to be run for the service, flap detection must be enabled
on a program-wide basis as well.
"""
self.run('ENABLE_SVC_FLAP_DETECTION', host_name, service_description)
def enable_svc_notifications(self, host_name, service_description):
"""
Enables notifications for a particular service. Notifications will be sent out
for the service only if notifications are enabled on a program-wide basis as
well.
"""
self.run('ENABLE_SVC_NOTIFICATIONS', host_name, service_description)
def process_file(self, file_name, delete):
"""
Directs Nagios to process all external commands that are found in the file
specified by the <file_name> argument. If the <delete> option is non-zero, the
file will be deleted once it has been processes. If the <delete> option is set
to zero, the file is left untouched.
"""
self.run('PROCESS_FILE', file_name, delete)
def process_host_check_result(self, host_name, status_code, plugin_output):
"""
This is used to submit a passive check result for a particular host. The
"status_code" indicates the state of the host check and should be one of the
following: 0=UP, 1=DOWN, 2=UNREACHABLE. The "plugin_output" argument contains
the text returned from the host check, along with optional performance data.
"""
self.run('PROCESS_HOST_CHECK_RESULT', host_name, status_code, plugin_output)
def process_service_check_result(self, host_name, service_description, return_code, plugin_output):
"""
This is used to submit a passive check result for a particular service. The
"return_code" field should be one of the following: 0=OK, 1=WARNING, 2=CRITICAL,
3=UNKNOWN. The "plugin_output" field contains text output from the service
check, along with optional performance data.
"""
self.run('PROCESS_SERVICE_CHECK_RESULT', host_name, service_description, return_code, plugin_output)
def read_state_information(self, ):
"""
Causes Nagios to load all current monitoring status information from the state
retention file. Normally, state retention information is loaded when the Nagios
process starts up and before it starts monitoring. WARNING: This command will
cause Nagios to discard all current monitoring status information and use the
information stored in state retention file! Use with care.
"""
self.run('READ_STATE_INFORMATION', )
def remove_host_acknowledgement(self, host_name):
"""
This removes the problem acknowledgement for a particular host. Once the
acknowledgement has been removed, notifications can once again be sent out for
the given host.
"""
self.run('REMOVE_HOST_ACKNOWLEDGEMENT', host_name)
def remove_svc_acknowledgement(self, host_name, service_description):
"""
This removes the problem acknowledgement for a particular service. Once the
acknowledgement has been removed, notifications can once again be sent out for
the given service.
"""
self.run('REMOVE_SVC_ACKNOWLEDGEMENT', host_name, service_description)
def restart_program(self, ):
"""
Restarts the Nagios process.
"""
self.run('RESTART_PROGRAM', )
def save_state_information(self, ):
"""
Causes Nagios to save all current monitoring status information to the state
retention file. Normally, state retention information is saved before the
Nagios process shuts down and (potentially) at regularly scheduled intervals.
This command allows you to force Nagios to save this information to the state
retention file immediately. This does not affect the current status information
in the Nagios process.
"""
self.run('SAVE_STATE_INFORMATION', )
def schedule_and_propagate_host_downtime(self, host_name, start_time, end_time, fixed, trigger_id, duration, author, comment):
"""
Schedules downtime for a specified host and all of its children (hosts). If the
"fixed" argument is set to one (1), downtime will start and end at the times
specified by the "start" and "end" arguments. Otherwise, downtime will begin
between the "start" and "end" times and last for "duration" seconds. The
"start" and "end" arguments are specified in time_t format (seconds since the
UNIX epoch). The specified (parent) host downtime can be triggered by another
downtime entry if the "trigger_id" is set to the ID of another scheduled
downtime entry. Set the "trigger_id" argument to zero (0) if the downtime for
the specified (parent) host should not be triggered by another downtime entry.
"""
self.run('SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME', host_name, start_time, end_time, fixed, trigger_id, duration, author, comment)
def schedule_and_propagate_triggered_host_downtime(self, host_name, start_time, end_time, fixed, trigger_id, duration, author, comment):
"""
Schedules downtime for a specified host and all of its children (hosts). If the
"fixed" argument is set to one (1), downtime will start and end at the times
specified by the "start" and "end" arguments. Otherwise, downtime will begin
between the "start" and "end" times and last for "duration" seconds. The
"start" and "end" arguments are specified in time_t format (seconds since the
UNIX epoch). Downtime for child hosts are all set to be triggered by the
downtime for the specified (parent) host. The specified (parent) host downtime
can be triggered by another downtime entry if the "trigger_id" is set to the ID
of another scheduled downtime entry. Set the "trigger_id" argument to zero (0)
if the downtime for the specified (parent) host should not be triggered by
another downtime entry.
"""
self.run('SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME', host_name, start_time, end_time, fixed, trigger_id, duration, author, comment)
def schedule_forced_host_check(self, host_name, check_time):
"""
Schedules a forced active check of a particular host at "check_time". The
"check_time" argument is specified in time_t format (seconds since the UNIX
epoch). Forced checks are performed regardless of what time it is (e.g.
timeperiod restrictions are ignored) and whether or not active checks are
enabled on a host-specific or program-wide basis.
"""
self.run('SCHEDULE_FORCED_HOST_CHECK', host_name, check_time)
def schedule_forced_host_svc_checks(self, host_name, check_time):
"""
Schedules a forced active check of all services associated with a particular
host at "check_time". The "check_time" argument is specified in time_t format
(seconds since the UNIX epoch). Forced checks are performed regardless of what