-
Notifications
You must be signed in to change notification settings - Fork 3
/
host_template.php
2387 lines (2301 loc) · 93.2 KB
/
host_template.php
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
<?php
/*
Lilac - A Nagios Configuration Tool
Copyright (C) 2018 EyesOfNetwork Team
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* host_template.php
* Author: EyesOfNetwork Team ([email protected])
* Description:
* Provides interface to maintain host templates
*
*/
include_once('includes/config.inc');
if(!isset($_GET['section']))
$_GET['section'] = 'general';
if(isset($_GET['id'])) {
// Load template.
if(!$lilac->get_host_template_info($_GET['id'], $hostTemplate)) {
header("Location: templates.php");
die();
}
else {
// GET VALUES
$templateValues = $hostTemplate->getValues();
}
}
// Action Handlers
if(isset($_GET['request'])) {
if($_GET['request'] == "delete" && $_GET['section'] == 'autodiscovery') {
$filter = NagiosHostTemplateAutodiscoveryServicePeer::retrieveByPK($_GET['filter']);
if(!$filter || $filter->getHostTemplate() != $hostTemplate->getId()) {
$error = "That filter no longer exists.";
}
else {
$filter->delete();
$success = "Service filter deleted.";
}
}
if($_GET['request'] == "delete" && $_GET['section'] == 'groups') {
$c = new Criteria();
$c->add(NagiosHostgroupMembershipPeer::HOST_TEMPLATE, $_GET['id']);
$c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $_GET['hostgroup_id']);
$membership = NagiosHostgroupMembershipPeer::doSelectOne($c);
if($membership) {
$membership->delete();
$success = "Membership Deleted";
}
}
else if($_GET['request'] == "duplicate" && $_GET['section'] == 'services') {
$old_service = NagiosServicePeer::retrieveByPK($_GET['service_id']);
if($old_service) {
$new_service = $old_service->duplicate();
$name = $old_service->getDescription();
$new_service->setDescription($name."-".rand(1000,9999));
$new_service->save();
$success = "Service Duplicated";
}
else {
$error = "That service does not exist.";
}
}
else if($_GET['request'] == "delete" && $_GET['section'] == 'services') {
$service = NagiosServicePeer::retrieveByPK($_GET['service_id']);
if($service) {
$service->delete();
$success = "Service Deleted";
}
else {
$error = "That service does not exist.";
}
}
else if($_GET['request'] == "delete" && $_GET['section'] == 'general') {
$template = NagiosHostTemplatePeer::retrieveByPK($_GET['id']);
if($template) {
$template->delete();
$success = "Host template deleted.";
unset($_GET['id']);
header("Location: templates.php");
die();
}
else {
$error = "Host template does not exist.";
}
}
else if($_GET['request'] == "delete" && $_GET['section'] == 'inheritance') {
$c = new Criteria();
$c->add(NagiosHostTemplateInheritancePeer::SOURCE_TEMPLATE, $hostTemplate->getId());
$c->addAscendingOrderByColumn(NagiosHostTemplateInheritancePeer::ORDER);
$inheritanceList = NagiosHostTemplateInheritancePeer::doSelect($c);
$found = false;
for($counter = 0; $counter < count($inheritanceList); $counter++) {
if($inheritanceList[$counter]->getNagiosHostTemplateRelatedByTargetTemplate()->getId() == $_GET['template_id']) {
// Omg, we found it!
// Delete the inheritance
$inheritanceList[$counter]->delete();
// Okay, regrab the list
$newList = NagiosHostTemplateInheritancePeer::doSelect($c);
for($counter = 0; $counter < count($newList); $counter++) {
// Reordering
$newList[$counter]->setOrder($counter);
$newList[$counter]->save();
}
$success = "Removed template from inheritance list.";
}
}
if(empty($error)) {
$error = "Could not find that template specified.";
}
}
else if($_GET['request'] == "movedown" && $_GET['section'] == "inheritance") {
$c = new Criteria();
$c->add(NagiosHostTemplateInheritancePeer::SOURCE_TEMPLATE, $hostTemplate->getId());
$c->addAscendingOrderByColumn(NagiosHostTemplateInheritancePeer::ORDER);
$inheritanceList = NagiosHostTemplateInheritancePeer::doSelect($c);
$found = false;
for($counter = 0; $counter < count($inheritanceList); $counter++) {
if($inheritanceList[$counter]->getNagiosHostTemplateRelatedByTargetTemplate()->getId() == $_GET['template_id']) {
// Omg, we found it!
if($counter == (count($inheritanceList) -1)) {
// We're at the end of the array, we couldn't possibly move down more!
$error = "Cannot move that template down any further.";
break;
}
else {
$tempTemplate = $inheritanceList[$counter + 1];
$inheritanceList[$counter]->setOrder($inheritanceList[$counter]->getOrder() + 1);
$tempTemplate->setOrder($tempTemplate->getOrder() - 1);
$inheritanceList[$counter]->save();
$tempTemplate->save();
$success = "Template moved down in inheritance chain.";
$found = true;
break;
}
}
}
if(empty($error)) {
$error = "Could not find that template specified.";
}
}
else if($_GET['request'] == "moveup" && $_GET['section'] == "inheritance") {
$c = new Criteria();
$c->add(NagiosHostTemplateInheritancePeer::SOURCE_TEMPLATE, $hostTemplate->getId());
$c->addAscendingOrderByColumn(NagiosHostTemplateInheritancePeer::ORDER);
$inheritanceList = NagiosHostTemplateInheritancePeer::doSelect($c);
$found = false;
for($counter = 0; $counter < count($inheritanceList); $counter++) {
if($inheritanceList[$counter]->getNagiosHostTemplateRelatedByTargetTemplate()->getId() == $_GET['template_id']) {
// Omg, we found it!
if($counter == 0) {
// We're at the end of the array, we couldn't possibly move down more!
$error = "Cannot move that template up any further.";
break;
}
else {
$tempTemplate = $inheritanceList[$counter - 1];
$inheritanceList[$counter]->setOrder($inheritanceList[$counter]->getOrder() - 1);
$tempTemplate->setOrder($tempTemplate->getOrder() + 1);
$inheritanceList[$counter]->save();
$tempTemplate->save();
$success = "Template moved up in inheritance chain.";
$found = true;
break;
}
}
}
if(empty($error)) {
$error = "Could not find that template specified.";
}
}
if($_GET['request'] == "delete" && $_GET['section'] == 'contacts') {
if(!empty($_GET['contactgroup_id'])) {
$c = new Criteria();
$c->add(NagiosHostContactgroupPeer::HOST_TEMPLATE, $_GET['id']);
$c->add(NagiosHostcontactgroupPeer::CONTACTGROUP, $_GET['contactgroup_id']);
$membership = NagiosHostContactgroupPeer::doSelectOne($c);
if($membership) {
$membership->delete();
$success = "Contact Group Deleted";
}
}
else if(!empty($_GET['contact_id'])) {
$c = new Criteria();
$c->add(NagiosHostContactMemberPeer::TEMPLATE, $_GET['id']);
$c->add(NagiosHostcontactMemberPeer::CONTACT, $_GET['contact_id']);
$membership = NagiosHostContactMemberPeer::doSelectOne($c);
if($membership) {
$membership->delete();
$success = "Contact deleted.";
}
}
}
if($_GET['request'] == "delete" && $_GET['section'] == 'dependencies') {
$dependency = NagiosDependencyPeer::retrieveByPK($_GET['dependency_id']);
if($dependency) {
$dependency->delete();
$success = "Dependency deleted.";
}
}
if($_GET['request'] == "delete" && $_GET['section'] == 'escalations') {
// !!!!!!!!!!!!!! This is where we do dependency error checking
$lilac->delete_escalation($_GET['escalation_id']);
$success = "Escalation Deleted";
unset($tempData);
}
if($_GET['request'] == "delete" && $_GET['section'] == 'checkcommand') {
$commandParameter = NagiosHostCheckCommandParameterPeer::retrieveByPK($_GET['checkcommandparameter_id']);
if($commandParameter) {
$commandParameter->delete();
}
$success = "Check Command Parameter Deleted.";
}
if($_GET['request'] == "update" && $_GET['section'] == 'checkcommand') {
$commandParameter = NagiosHostCheckCommandParameterPeer::retrieveByPK($_GET['checkcommandparameter_id']);
$commandParameter->setParameter($_POST['param']);
$commandParameter->save();
$success = "Check Command Parameter Updated.";
}
if($_GET['request'] == "delete" && $_GET['section'] == 'customobjectvars') {
$customObjectVar = NagiosHostCustomObjectVarPeer::retrieveByPK($_GET['customobjectvariable_id']);
if($customObjectVar) {
$customObjectVar->delete();
}
$success = "Custom Object Variable Deleted.";
}
}
if(isset($_POST['request'])) {
$modifiedData = array();
if(isset($_POST['host_manage']) && count($_POST['host_manage'])) {
foreach( $_POST['host_manage'] as $key=>$value) {
if( is_array( $value)) {
$modifiedData[$key] = $value;
} else {
$modifiedData[$key] = (string)trim($value);
}
}
}
if($_POST['request'] == 'host_template_modify_general') {
if($modifiedData['template_name'] != $hostTemplate->getName() && $lilac->hosttemplate_exists($modifiedData['template_name'])) {
$error = "A host template with that name already exists!";
}
else {
// Field Error Checking
if(count($modifiedData)) {
foreach($modifiedData as $tempVariable)
$tempVariable = trim($tempVariable);
}
if($modifiedData['template_name'] == '' || $modifiedData['template_description'] == '') {
$addError = 1;
$error = "Incorrect values for fields. Please verify.";
}
// All is well for error checking, modify the template.
else {
$hostTemplate->setName($modifiedData['template_name']);
$hostTemplate->setDescription($modifiedData['template_description']);
$hostTemplate->save();
$success = "Template modified.";
unset($_GET['edit']);
}
}
}
else if($_POST['request'] == "add_template_command") {
$template = NagiosHostTemplatePeer::retrieveByPK($_POST['hostmanage']['template_add']['template_id']);
if(!$template) {
$error = "That host template is not found.";
}
else {
// We need to get the count of templates already inherited
$templateList = $hostTemplate->getNagiosHostTemplateInheritances();
foreach($templateList as $tempTemplate) {
if($tempTemplate->getId() == $_POST['hostmanage']['template_add']['template_id']) {
$error = "That template already exists in the inheritance chain.";
}
}
if(empty($error)) {
$newInheritance = new NagiosHostTemplateInheritance();
$newInheritance->setNagiosHostTemplateRelatedBySourceTemplate($hostTemplate);
$newInheritance->setNagiosHostTemplateRelatedByTargetTemplate($template);
$newInheritance->setOrder(count($templateList));
try {
$newInheritance->save();
$success = "Template added to inheritance chain.";
}
catch(Exception $e) {
$error = $e->getMessage();
}
}
}
}
else if($_POST['request'] == 'host_template_modify_checks') {
if(count($modifiedData)) {
foreach($modifiedData as $tempVariable)
$tempVariable = trim($tempVariable);
}
if((isset($modifiedData['max_check_attempts_include']) && !is_numeric($modifiedData['max_check_attempts'])) || (isset($modifiedData['max_check_attempts_include']) && !($modifiedData['max_check_attempts'] >= 1)) || (isset($modifiedData['freshness_threshold_include']) && !($modifiedData['freshness_threshold'] >= 0))) {
$addError = 1;
$error = "Incorrect values for fields. Please verify.";
}
// All is well for error checking, modify the template.
else {
// Let's modify our host template
if(isset($modifiedData['initial_state'])) {
$hostTemplate->setInitialState($modifiedData['initial_state']);
}
else {
$hostTemplate->setInitialState(null);
}
if(isset($modifiedData['active_checks_enabled'])) {
$hostTemplate->setActiveChecksEnabled($modifiedData['active_checks_enabled']);
}
else {
$hostTemplate->setActiveChecksEnabled(null);
}
if(isset($modifiedData['passive_checks_enabled'])) {
$hostTemplate->setPassiveChecksEnabled($modifiedData['passive_checks_enabled']);
}
else {
$hostTemplate->setPassiveChecksEnabled(null);
}
if(isset($modifiedData['check_period']) && $modifiedData['check_period'] != 0) {
$hostTemplate->setCheckPeriod(NagiosTimeperiodPeer::retrieveByPK($modifiedData['check_period'])->getId());
}
else {
$hostTemplate->setCheckPeriod(null);
}
if(isset($modifiedData['check_command']) && $modifiedData['check_command'] != 0) {
$hostTemplate->setCheckCommand(NagiosCommandPeer::retrieveByPK($modifiedData['check_command'])->getId());
}
else {
$hostTemplate->setCheckCommand(null);
}
if(isset($modifiedData['retry_interval'])) {
$hostTemplate->setRetryInterval($modifiedData['retry_interval']);
}
else {
$hostTemplate->setRetryInterval(null);
}
if(isset($modifiedData['max_check_attempts'])) {
$hostTemplate->setMaximumCheckAttempts($modifiedData['max_check_attempts']);
}
else {
$hostTemplate->setMaximumCheckAttempts(null);
}
if(isset($modifiedData['check_interval'])) {
$hostTemplate->setCheckInterval($modifiedData['check_interval']);
}
else {
$hostTemplate->setCheckInterval(null);
}
if(isset($modifiedData['obsess_over_host'])) {
$hostTemplate->setObsessOverHost($modifiedData['obsess_over_host']);
}
else {
$hostTemplate->setObsessOverHost(null);
}
if(isset($modifiedData['check_freshness'])) {
$hostTemplate->setCheckFreshness($modifiedData['check_freshness']);
}
else {
$hostTemplate->setCheckFreshness(null);
}
if(isset($modifiedData['freshness_threshold'])) {
$hostTemplate->setFreshnessThreshold($modifiedData['freshness_threshold']);
}
else {
$hostTemplate->setFreshnessThreshold(null);
}
if(isset($modifiedData['event_handler']) && $modifiedData['event_handler'] !=0) {
$hostTemplate->setEventHandler(NagiosCommandPeer::retrieveByPK($modifiedData['event_handler'])->getId());
}
else {
$hostTemplate->setEventHandler(null);
}
if(isset($modifiedData['event_handler_enabled'])) {
$hostTemplate->setEventHandlerEnabled($modifiedData['event_handler_enabled']);
}
else {
$hostTemplate->setEventHandlerEnabled(null);
}
if(isset($modifiedData['failure_prediction_enabled'])) {
$hostTemplate->setFailurePredictionEnabled($modifiedData['failure_prediction_enabled']);
}
else {
$hostTemplate->setFailurePredictionEnabled(null);
}
$hostTemplate->save();
unset($_GET['edit']);
$success = "Host template modified";
}
}
else if($_POST['request'] == 'host_template_modify_flapping') {
// Field Error Checking
if(count($modifiedData)) {
foreach($modifiedData as $tempVariable)
$tempVariable = trim($tempVariable);
}
if((isset($modifiedData['low_flap_threshold']) && $modifiedData['low_flap_threshold'] < 0) || (isset($modifiedData['high_flap_threshold']) && $modifiedData['high_flap_threshold'] < 0)) {
$addError = 1;
$error = "Incorrect values for fields. Please verify.";
}
// All is well for error checking, modify the command.
else {
// Modify flapping information
if(isset($modifiedData['flap_detection_enabled'])) {
$hostTemplate->setFlapDetectionEnabled($modifiedData['flap_detection_enabled']);
}
else {
$hostTemplate->setFlapDetectionEnabled(null);
}
if(!isset($_POST['host_manage_checkboxes']) || !isset($_POST['host_manage_checkboxes']['flap_detection_options'])) {
$hostTemplate->setFlapDetectionOnUp(null);
$hostTemplate->setFlapDetectionOnDown(null);
$hostTemplate->setFlapDetectionOnUnreachable(null);
}
else {
if(isset($_POST['host_manage']['flap_detection_on_up'])) {
$hostTemplate->setFlapDetectionOnUp(true);
}
else {
$hostTemplate->setFlapDetectionOnUp(false);
}
if(isset($_POST['host_manage']['flap_detection_on_down'])) {
$hostTemplate->setFlapDetectionOnDown(true);
}
else {
$hostTemplate->setFlapDetectionOnDown(false);
}
if(isset($_POST['host_manage']['flap_detection_on_unreachable'])) {
$hostTemplate->setFlapDetectionOnUnreachable(true);
}
else {
$hostTemplate->setFlapDetectionOnUnreachable(false);
}
}
if(isset($modifiedData['low_flap_threshold'])) {
$hostTemplate->setLowFlapThreshold($modifiedData['low_flap_threshold']);
}
else {
$hostTemplate->setLowFlapThreshold(null);
}
if(isset($modifiedData['high_flap_threshold'])) {
$hostTemplate->setHighFlapThreshold($modifiedData['high_flap_threshold']);
}
else {
$hostTemplate->setHighFlapThreshold(null);
}
$hostTemplate->save();
unset($modifiedData);
$success = "Host template modified.";
unset($_GET['edit']);
}
}
else if($_POST['request'] == 'host_template_modify_logging') {
// Field Error Checking
// None required for this process
// All is well for error checking, modify the host template.
if(isset($modifiedData['process_perf_data'])) {
$hostTemplate->setProcessPerfData($modifiedData['process_perf_data']);
}
else {
$hostTemplate->setProcessPerfData(null);
}
if(isset($modifiedData['retain_status_information'])) {
$hostTemplate->setRetainStatusInformation($modifiedData['retain_status_information']);
}
else {
$hostTemplate->setRetainStatusInformation(null);
}
if(isset($modifiedData['retain_nonstatus_information'])) {
$hostTemplate->setRetainNonstatusInformation($modifiedData['retain_nonstatus_information']);
}
else {
$hostTemplate->setRetainNonstatusInformation(null);
}
$hostTemplate->save();
unset($modifiedData);
$success = "Host template modified.";
unset($_GET['edit']);
}
else if($_POST['request'] == 'host_template_modify_notifications') {
// Field Error Checking
if(count($modifiedData)) {
foreach($modifiedData as $tempVariable)
$tempVariable = trim($tempVariable);
}
if(isset($_POST['host_manage_enablers']['notification_interval']) &&
($modifiedData['notification_interval'] == '' || $modifiedData['notification_interval'] < 0 || !is_numeric($modifiedData['notification_interval']))) {
$error = "Incorrect values for fields. Please verify.";
}
// All is well for error checking, modify the command.
else {
if(!isset($_POST['host_manage_checkboxes']) || !isset($_POST['host_manage_checkboxes']['notification_options'])) {
$hostTemplate->setNotificationOnDown(null);
$hostTemplate->setNotificationOnUnreachable(null);
$hostTemplate->setNotificationOnRecovery(null);
$hostTemplate->setNotificationOnFlapping(null);
$hostTemplate->setNotificationOnScheduledDowntime(null);
}
else {
if(isset($_POST['host_manage']['notification_on_down'])) {
$hostTemplate->setNotificationOnDown(true);
}
else {
$hostTemplate->setNotificationOnDown(false);
}
if(isset($_POST['host_manage']['notification_on_unreachable'])) {
$hostTemplate->setNotificationOnUnreachable(true);
}
else {
$hostTemplate->setNotificationOnUnreachable(false);
}
if(isset($_POST['host_manage']['notification_on_recovery'])) {
$hostTemplate->setNotificationOnRecovery(true);
}
else {
$hostTemplate->setNotificationOnRecovery(false);
}
if(isset($_POST['host_manage']['notification_on_flapping'])) {
$hostTemplate->setNotificationOnFlapping(true);
}
else {
$hostTemplate->setNotificationOnFlapping(false);
}
if(isset($_POST['host_manage']['notification_on_scheduled_downtime'])) {
$hostTemplate->setNotificationOnScheduledDowntime(true);
}
else {
$hostTemplate->setNotificationOnScheduledDowntime(false);
}
}
if(!isset($_POST['host_manage_checkboxes']) || !isset($_POST['host_manage_checkboxes']['stalking_options'])) {
$hostTemplate->setStalkingOnUp(null);
$hostTemplate->setStalkingOnDown(null);
$hostTemplate->setStalkingOnUnreachable(null);
}
else {
if(isset($_POST['host_manage']['stalking_on_up'])) {
$hostTemplate->setStalkingOnUp(true);
}
else {
$hostTemplate->setStalkingOnUp(false);
}
if(isset($_POST['host_manage']['stalking_on_down'])) {
$hostTemplate->setStalkingOnDown(true);
}
else {
$hostTemplate->setStalkingOnDown(false);
}
if(isset($_POST['host_manage']['stalking_on_unreachable'])) {
$hostTemplate->setStalkingOnUnreachable(true);
}
else {
$hostTemplate->setStalkingOnUnreachable(false);
}
}
if(isset($modifiedData['first_notification_delay'])) {
$hostTemplate->setFirstNotificationDelay($modifiedData['first_notification_delay']);
}
else {
$hostTemplate->setFirstNotificationDelay(null);
}
if(isset($modifiedData['notifications_enabled'])) {
$hostTemplate->setNotificationsEnabled($modifiedData['notifications_enabled']);
}
else {
$hostTemplate->setNotificationsEnabled(null);
}
if(isset($modifiedData['notification_interval'])) {
$hostTemplate->setNotificationInterval($modifiedData['notification_interval']);
}
else {
$hostTemplate->setNotificationInterval(null);
}
if(isset($modifiedData['notification_period'])) {
$hostTemplate->setNotificationPeriod(NagiosTimeperiodPeer::retrieveByPK($modifiedData['notification_period'])->getId());
}
else {
$hostTemplate->setNotificationPeriod(null);
}
$hostTemplate->save();
// Remove session data
unset($modifiedData);
$success = "Host template modified.";
unset($_GET['edit']);
}
}
else if($_POST['request'] == 'add_member_command') {
if($lilac->host_template_has_hostgroup($_GET['id'], $modifiedData['group_add']['hostgroup_id'])) {
$error = "That host group already exists in that list!";
}
else {
$lilac->add_hostgroup_template_member($modifiedData['group_add']['hostgroup_id'], $modifiedData['group_add']['host_id']);
$success = "Host Template Added To Host Group.";
unset($modifiedData);
}
}
else if($_POST['request'] == 'command_parameter_add') {
// All is well for error checking, modify the command.
$lilac->add_host_template_command_parameter($_GET['id'], $modifiedData);
// Remove session data
unset($modifiedData);
$success = "Command Parameter added.";
}
else if($_POST['request'] == 'custom_object_variable_add') {
try
{
// All is well for error checking, modify the command.
$lilac->add_host_template_custom_object_variable($_GET['id'], $modifiedData);
// Remove session data
unset($host);
$success = "Custom object variable added.";
}
catch(Exception $e)
{
$error = $e->getMessage();
}
}
if($_POST['request'] == 'update_host_extended') {
if(isset($modifiedData['notes'])) {
$hostTemplate->setNotes($modifiedData['notes']);
}
else {
$hostTemplate->setNotes(null);
}
if(isset($modifiedData['notes_url'])) {
$hostTemplate->setNotesUrl($modifiedData['notes_url']);
}
else {
$hostTemplate->setNotesUrl(null);
}
if(isset($modifiedData['action_url'])) {
$hostTemplate->setActionUrl($modifiedData['action_url']);
}
else {
$hostTemplate->setActionUrl(null);
}
if(isset($modifiedData['icon_image'])) {
$hostTemplate->setIconImage($modifiedData['icon_image']);
}
else {
$hostTemplate->setIconImage(null);
}
if(isset($modifiedData['icon_image_alt'])) {
$hostTemplate->setIconImageAlt($modifiedData['icon_image_alt']);
}
else {
$hostTemplate->setIconImageAlt(null);
}
if(isset($modifiedData['vrml_image'])) {
$hostTemplate->setVrmlImage($modifiedData['vrml_image']);
}
else {
$hostTemplate->setVrmlImage(null);
}
if(isset($modifiedData['statusmap_image'])) {
$hostTemplate->setStatusmapImage($modifiedData['statusmap_image']);
}
else {
$hostTemplate->setStatusmapImage(null);
}
if(isset($modifiedData['two_d_coords'])) {
$hostTemplate->setTwoDCoords($modifiedData['two_d_coords']);
}
else {
$hostTemplate->setTwoDCoords(null);
}
if(isset($modifiedData['three_d_coords'])) {
$hostTemplate->setThreeDCoords($modifiedData['three_d_coords']);
}
else {
$hostTemplate->setThreeDCoords(null);
}
$hostTemplate->save();
$success = "Updated Host Template Extended Information";
}
else if($_POST['request'] == 'add_contact_command') {
$c = new Criteria();
$c->add(NagiosHostContactMemberPeer::TEMPLATE, $_GET['id']);
$c->add(NagiosHostContactMemberPeer::CONTACT, $_POST['host_manage']['contact_add']['contact_id']);
$membership = NagiosHostContactMemberPeer::doSelectOne($c);
if($membership) {
$error = "That contact already exists in that list!";
}
else {
$tempContact = NagiosContactPeer::retrieveByPk($_POST['host_manage']['contact_add']['contact_id']);
if($tempContact) {
$membership = new NagiosHostContactMember();
$membership->setTemplate($_GET['id']);
$membership->setNagiosContact($tempContact);
$membership->save();
$success = "New Host Template Contact Link added.";
}
else {
$error = "That contact is not found.";
}
}
}
else if($_POST['request'] == 'add_contactgroup_command') {
$c = new Criteria();
$c->add(NagiosHostContactgroupPeer::HOST_TEMPLATE, $_GET['id']);
$c->add(NagiosHostContactgroupPeer::CONTACTGROUP, $_POST['host_manage']['contactgroup_add']['contactgroup_id']);
$membership = NagiosHostContactgroupPeer::doSelectOne($c);
if($membership) {
$error = "That contact group already exists in that list!";
}
else {
$tempGroup = NagiosContactGroupPeer::retrieveByPk($_POST['host_manage']['contactgroup_add']['contactgroup_id']);
if($tempGroup) {
$membership = new NagiosHostContactgroup();
$membership->setHostTemplate($_GET['id']);
$membership->setNagiosContactGroup($tempGroup);
$membership->save();
$success = "New Host Template Contact Group Link added.";
}
else {
$error = "That contact group is not found.";
}
}
}
else if($_POST['request'] == 'host_template_modify_autodiscovery') {
// Field Error Checking
if(count($modifiedData)) {
foreach($modifiedData as $tempVariable)
$tempVariable = trim($tempVariable);
}
// All is well for error checking, modify the command.
if(isset($modifiedData['autodiscovery_address_filter'])) {
$hostTemplate->setAutodiscoveryAddressFilter($modifiedData['autodiscovery_address_filter']);
}
else {
$hostTemplate->setAutodiscoveryAddressFilter(null);
}
if(isset($modifiedData['autodiscovery_hostname_filter'])) {
$hostTemplate->setAutodiscoveryHostnameFilter($modifiedData['autodiscovery_hostname_filter']);
}
else {
$hostTemplate->setAutodiscoveryHostnameFilter(null);
}
if(isset($modifiedData['autodiscovery_os_family_filter'])) {
$hostTemplate->setAutodiscoveryOsFamilyFilter($modifiedData['autodiscovery_os_family_filter']);
}
else {
$hostTemplate->setAutodiscoveryOsFamilyFilter(null);
}
if(isset($modifiedData['autodiscovery_os_generation_filter'])) {
$hostTemplate->setAutodiscoveryOsGenerationFilter($modifiedData['autodiscovery_os_generation_filter']);
}
else {
$hostTemplate->setAutodiscoveryOsGenerationFilter(null);
}
if(isset($modifiedData['autodiscovery_os_vendor_filter'])) {
$hostTemplate->setAutodiscoveryOsVendorFilter($modifiedData['autodiscovery_os_vendor_filter']);
}
else {
$hostTemplate->setAutodiscoveryOsVendorFilter(null);
}
$hostTemplate->save();
unset($modifiedData);
$success = "Host template modified.";
unset($_GET['edit']);
}
else if($_POST['request'] == 'host_template_add_autodiscovery_service') {
if(count($modifiedData)) {
foreach($modifiedData as $tempVariable)
$tempVariable = trim($tempVariable);
}
if(empty($modifiedData['protocol']) || empty($modifiedData['port']) || !is_numeric($modifiedData['port'])) {
$error = "Port is required and must be numeric for Auto-Discovery service filter.";
}
else {
// Error checking is good, let's create a service filter
$serviceFilter = new NagiosHostTemplateAutodiscoveryService();
$serviceFilter->setExtraInformation($modifiedData['extra_information']);
$serviceFilter->setNagiosHostTemplate($hostTemplate);
$serviceFilter->setName($modifiedData['name']);
$serviceFilter->setPort($modifiedData['port']);
$serviceFilter->setProduct($modifiedData['product']);
$serviceFilter->setProtocol($modifiedData['protocol']);
$serviceFilter->setVersion($modifiedData['version']);
$serviceFilter->save();
$success = "Auto-Discovery Service Filter Created";
}
}
}
if(isset($_GET['id'])) {
// Load template.
if(!$lilac->get_host_template_info($_GET['id'], $hostTemplate)) {
header("Location: templates.php");
die();
}
else {
// GET VALUES
$templateValues = $hostTemplate->getValues();
// Check to see if we inherit from another template
}
}
// To create a "default" command
$command_list[] = array("command_id" => 0, "command_name" => "None");
$lilac->return_command_list($tempList);
foreach($tempList as $command) {
$command_list[] = array("command_id" => $command->getId(), "command_name" => $command->getName());
}
$period_list = array();
$lilac->return_period_list($tempList);
foreach($tempList as $period) {
$period_list[] = array("timeperiod_id" => $period->getId(), "timeperiod_name" => $period->getName());
}
$initialState_list = array();
$initialState_list[] = array('value' => 'o', 'label' => 'Up');
$initialState_list[] = array('value' => 'd', 'label' => 'Down');
$initialState_list[] = array('value' => 'u', 'label' => 'Unreachable');
// Build subnav
$subnav = array(
'general' => 'General',
'inheritance' => 'Inheritance',
'hosts' => 'Hosts',
'checks' => 'Checks',
'flapping' => 'Flapping',
'logging' => 'Logging',
'notifications' => 'Notifications',
'services' => 'Services',
'groups' => 'Group Memberships',
'contacts' => 'Contacts',
'extended' => 'Extended Information',
'dependencies' => 'Dependencies',
'escalations' => 'Escalations',
'customobjectvars' => 'Custom Object Variables'
);
if(isset($templateValues['check_command'])) {
$subnav['checkcommand'] = 'Check Command Parameters';
}
$subnav['autodiscovery'] = 'Auto-Discovery Filters';
print_header("Host Template Editor");
if(isset($_GET['id'])) {
print_window_header("Template Info for " . $hostTemplate->getName(), "100%");
print_subnav($subnav, $_GET['section'], "section", $_SERVER['PHP_SELF'] . "?id=" . $_GET['id']);
$host_template_icon_image = $path_config['image_root'] . "server.gif";
if($_GET['section'] == 'general') {
?>
<table width="100%" border="0">
<tr>
<td width="100" align="center" valign="top">
<img src="<?php echo $host_template_icon_image;?>" />
</td>
<td valign="top">
<?php
if(isset($_GET['edit'])) { // We're editing general information
?>
<form name="host_manage" method="post" action="host_template.php?id=<?php echo $_GET['id'];?>§ion=general&edit=1">
<input type="hidden" name="request" value="host_template_modify_general" />
<input type="hidden" name="host_template_id" value="<?php echo $hostTemplate->getId();?>">
<b>Template Name:</b><br />
<input type="text" size="40" name="host_manage[template_name]" value="<?php echo $hostTemplate->getName();?>">
<?php echo $lilac->element_desc("template_name", "nagios_host_template_desc"); ?><br />
<br />
<b>Description:</b><br />
<input type="text" size="80" name="host_manage[template_description]" value="<?php echo $hostTemplate->getDescription();?>">
<?php echo $lilac->element_desc("template_description", "nagios_host_template_desc"); ?><br />
<br />
<br />
<input class="btn btn-primary" type="submit" value="Update General" /> <a class="btn btn-default" href="host_template.php?id=<?php echo $hostTemplate->getId();?>§ion=general">Cancel</a>
<?php
}
else {
?>
<b>Template Name:</b> <?php echo $hostTemplate->getName();?><br />
<b>Description:</b> <?php echo $hostTemplate->getDescription();?><br />
<br />
<a class="btn btn-primary" href="host_template.php?id=<?php echo $_GET['id'];?>§ion=general&edit=1">Edit</a>
<?php
}
?>
</td>
</tr>
</table>
<br />
<a class="btn btn-danger" href="host_template.php?id=<?php echo $_GET['id'];?>&request=delete" onClick="javascript:return confirmDelete();">Delete This Host Template</a>
<?php
}
if($_GET['section'] == 'inheritance') {
$templateInheritances = $hostTemplate->getNagiosHostTemplateInheritances();
$numOfTemplates = count($templateInheritances);
$exclude_list = array();
$exclude_list[] = $hostTemplate->getId();
if($numOfTemplates) {
foreach($templateInheritances as $template) {
$exclude_list[] = $template->getId();
}
}
$c=new Criteria();
$c->addAscendingOrderByColumn(NagiosHostTemplatePeer::NAME);
$templateList = NagiosHostTemplatePeer::doSelect($c);
?>
<table width="100%" border="0">
<tr>
<td width="100" align="center" valign="top">
<img src="<?php echo $host_template_icon_image;?>" />
</td>
<td valign="top">
<table width="100%" align="center" cellspacing="0" cellpadding="2" border="0">
<tr class="altTop">
<td colspan="4">Host Templates To Inherit From (Top to Bottom):</td>
</tr>
<?php
for($counter = 0; $counter < $numOfTemplates; $counter++) {
if($counter % 2) {
?>
<tr class="altRow1">
<?php
}
else {
?>
<tr class="altRow2">
<?php
}
?>
<td height="20" width="80" class="altLeft"><?php if($numOfTemplates > 1 && $counter > 0) { ?><a class="btn btn-primary btn-xs" href="host_template.php?id=<?php echo $_GET['id'];?>§ion=inheritance&request=moveup&template_id=<?php echo $templateInheritances[$counter]->getId();?>">Move Up</a><?php }?></td>
<td height="20" width="100" class="altLeft"><?php if($numOfTemplates > 1 && $counter < ($numOfTemplates -1)) { ?><a class="btn btn-primary btn-xs" href="host_template.php?id=<?php echo $_GET['id'];?>§ion=inheritance&request=movedown&template_id=<?php echo $templateInheritances[$counter]->getId();?>">Move Down</a><?php }?></td>
<td height="20" width="80" nowrap="nowrap" class="altLeft"> <a class="btn btn-danger btn-xs" href="host_template.php?id=<?php echo $_GET['id'];?>§ion=inheritance&request=delete&template_id=<?php echo $templateInheritances[$counter]->getId();?>" onClick="javascript:return confirmDelete();">Delete</a></td>
<td height="20" class="altRight"><b><?php echo $templateInheritances[$counter]->getName();?></b></td>
</tr>
<?php
}
?>
</table>
<br />
<br />
<form name="template_add" method="post" action="host_template.php?id=<?php echo $_GET['id'];?>§ion=inheritance">
<input type="hidden" name="request" value="add_template_command" />
<b>Add Template To Inherit From:</b> <?php print_object_select("hostmanage[template_add][template_id]", $templateList, "getId", "getName", NULL, true, $exclude_list);?> <input class="btn btn-primary" type="submit" value="Add Template"><br />
<br />
</form>
</td>
</tr>
</table>
<?php
}
if($_GET['section'] == 'hosts') {
$members = $hostTemplate->getAffectedHosts();
$numOfMembers = count($members);
?>