Add test directory from incubator
This contains only php tests, although the folders for javascript and ui are created now refs #4212
This commit is contained in:
parent
d5df734c77
commit
4b2b28b65b
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Zend_View_Helper_Perfdata
|
||||
* Created Thu, 24 Jan 2013 12:56:08 +0000
|
||||
*
|
||||
**/
|
||||
class Zend_View_Helper_PerfdataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Zend_View_Helper_Perfdata::Perfdata()
|
||||
*
|
||||
**/
|
||||
public function testPerfdata()
|
||||
{
|
||||
$this->markTestIncomplete('testPerfdata is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Zend_View_Helper_Qurl
|
||||
* Created Thu, 24 Jan 2013 12:56:08 +0000
|
||||
*
|
||||
**/
|
||||
class Zend_View_Helper_QurlTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Zend_View_Helper_QUrl::QUrl()
|
||||
*
|
||||
**/
|
||||
public function testQUrl()
|
||||
{
|
||||
$this->markTestIncomplete('testQUrl is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
if(!class_exists('Zend_View_Helper_Abstract')) {
|
||||
abstract class Zend_View_Helper_Abstract {
|
||||
public $basename;
|
||||
|
||||
public function __construct($basename = '') {
|
||||
$this->view = $this;
|
||||
$this->basename = $basename;
|
||||
}
|
||||
|
||||
public function baseUrl($url) {
|
||||
return $this->basename.$url;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
require('../application/views/helpers/Qlink.php');
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Zend_View_Helper_Qlink
|
||||
* Created Thu, 24 Jan 2013 12:56:08 +0000
|
||||
*
|
||||
**/
|
||||
class Zend_View_Helper_QlinkTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
|
||||
public function testURLPathParameter()
|
||||
{
|
||||
$helper = new Zend_View_Helper_Qlink();
|
||||
$pathTpl = "path/%s/to/%s";
|
||||
$this->assertEquals(
|
||||
"path/param1/to/param2",
|
||||
$helper->getFormattedURL($pathTpl,array('param1','param2'))
|
||||
);
|
||||
}
|
||||
|
||||
public function testUrlGETParameter()
|
||||
{
|
||||
$helper = new Zend_View_Helper_Qlink();
|
||||
$pathTpl = 'path';
|
||||
$this->assertEquals(
|
||||
'path?param1=value1&param2=value2',
|
||||
$helper->getFormattedURL($pathTpl,array('param1'=>'value1','param2'=>'value2'))
|
||||
);
|
||||
}
|
||||
|
||||
public function testMixedParameters()
|
||||
{
|
||||
$helper = new Zend_View_Helper_Qlink();
|
||||
$pathTpl = 'path/%s/to/%s';
|
||||
$this->assertEquals(
|
||||
'path/path1/to/path2?param1=value1&param2=value2',
|
||||
$helper->getFormattedURL($pathTpl,array(
|
||||
'path1','path2',
|
||||
'param1'=>'value1',
|
||||
'param2'=>'value2'))
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Test error case
|
||||
public function testWrongUrl() {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Zend_View_Helper_Renderserviceperfdata
|
||||
* Created Thu, 24 Jan 2013 12:56:08 +0000
|
||||
*
|
||||
**/
|
||||
class Zend_View_Helper_RenderserviceperfdataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Zend_View_Helper_RenderServicePerfdata::RenderServicePerfdata()
|
||||
*
|
||||
**/
|
||||
public function testRenderServicePerfdata()
|
||||
{
|
||||
$this->markTestIncomplete('testRenderServicePerfdata is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Zend_View_Helper_RenderServicePerfdata::RenderDiskPie()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testRenderDiskPie()
|
||||
{
|
||||
$this->markTestIncomplete('testRenderDiskPie is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Zend_View_Helper_Timesince
|
||||
* Created Wed, 16 Jan 2013 15:15:14 +0000
|
||||
*
|
||||
**/
|
||||
class Zend_View_Helper_TimesinceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Zend_View_Helper_TimeSince::TimeSince()
|
||||
*
|
||||
**/
|
||||
public function testTimeSince()
|
||||
{
|
||||
$this->markTestIncomplete('testTimeSince is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Zend_View_Helper_TimeSince::ShowHourMin()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testShowHourMin()
|
||||
{
|
||||
$this->markTestIncomplete('testShowHourMin is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Monlib_Gui_Util
|
||||
* Created Wed, 16 Jan 2013 15:15:14 +0000
|
||||
*
|
||||
**/
|
||||
class Monlib_Gui_UtilTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Monlib_Gui_Util::ShowTimeSince()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testShowTimeSince()
|
||||
{
|
||||
$this->markTestIncomplete('testShowTimeSince is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monlib_Gui_Util::ShowHourMin()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testShowHourMin()
|
||||
{
|
||||
$this->markTestIncomplete('testShowHourMin is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monlib_Gui_Util::ShowSeconds()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testShowSeconds()
|
||||
{
|
||||
$this->markTestIncomplete('testShowSeconds is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monlib_Gui_Util::ShowTime()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testShowTime()
|
||||
{
|
||||
$this->markTestIncomplete('testShowTime is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monlib_Gui_Util::GetHostStateClassName()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testGetHostStateClassName()
|
||||
{
|
||||
$this->markTestIncomplete('testGetHostStateClassName is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monlib_Gui_Util::GetHostStateName()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testGetHostStateName()
|
||||
{
|
||||
$this->markTestIncomplete('testGetHostStateName is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Monlib_Gui_Util::GetServiceStateName()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testGetServiceStateName()
|
||||
{
|
||||
$this->markTestIncomplete('testGetServiceStateName is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
# Tools for testing icinga2
|
||||
#
|
||||
|
||||
extcmd_test just receives an icinga external command from stdin and returns whether it's a recognized command
|
||||
or if there are any errors. To build it, just type gcc -o extcmd_test ./extcmd_test.c, there shouldn't be any
|
||||
dependencies that need linker flags
|
|
@ -0,0 +1,520 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* Icinga Common Header File
|
||||
*
|
||||
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
|
||||
* Copyright (c) 2009-2012 Nagios Core Development Team and Community Contributors
|
||||
* Copyright (c) 2009-2012 Icinga Development Team (http://www.icinga.org)
|
||||
*
|
||||
* License:
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
************************************************************************/
|
||||
|
||||
#include "shared.h"
|
||||
|
||||
#define PROGRAM_NAME "Icinga"
|
||||
#define PROGRAM_NAME_UC "ICINGA"
|
||||
#define PROGRAM_NAME_LC "icinga"
|
||||
#define PROGRAM_VERSION "1.8.0dev"
|
||||
#define PROGRAM_MODIFICATION_DATE "10-17-2012"
|
||||
|
||||
/*#define DEBUG_CHECK_IPC 1 */
|
||||
/*#define DEBUG_CHECK_IPC2 1*/
|
||||
|
||||
|
||||
|
||||
/* daemon is thread safe */
|
||||
#ifdef NSCORE
|
||||
#ifndef _REENTRANT
|
||||
#define _REENTRANT
|
||||
#endif
|
||||
#ifndef _THREAD_SAFE
|
||||
#define _THREAD_SAFE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Experimental performance tweaks - use with caution */
|
||||
#undef USE_MEMORY_PERFORMANCE_TWEAKS
|
||||
|
||||
/* my_free has been freed from bondage as a function */
|
||||
#define my_free(ptr) do { if(ptr) { free(ptr); ptr = NULL; } } while(0)
|
||||
|
||||
|
||||
|
||||
/***************************** COMMANDS *********************************/
|
||||
|
||||
#define CMD_NONE 0
|
||||
|
||||
#define CMD_ADD_HOST_COMMENT 1
|
||||
#define CMD_DEL_HOST_COMMENT 2
|
||||
|
||||
#define CMD_ADD_SVC_COMMENT 3
|
||||
#define CMD_DEL_SVC_COMMENT 4
|
||||
|
||||
#define CMD_ENABLE_SVC_CHECK 5
|
||||
#define CMD_DISABLE_SVC_CHECK 6
|
||||
|
||||
#define CMD_SCHEDULE_SVC_CHECK 7
|
||||
|
||||
#define CMD_DELAY_SVC_NOTIFICATION 9
|
||||
|
||||
#define CMD_DELAY_HOST_NOTIFICATION 10
|
||||
|
||||
#define CMD_DISABLE_NOTIFICATIONS 11
|
||||
#define CMD_ENABLE_NOTIFICATIONS 12
|
||||
|
||||
#define CMD_RESTART_PROCESS 13
|
||||
#define CMD_SHUTDOWN_PROCESS 14
|
||||
|
||||
#define CMD_ENABLE_HOST_SVC_CHECKS 15
|
||||
#define CMD_DISABLE_HOST_SVC_CHECKS 16
|
||||
|
||||
#define CMD_SCHEDULE_HOST_SVC_CHECKS 17
|
||||
|
||||
#define CMD_DELAY_HOST_SVC_NOTIFICATIONS 19 /* currently unimplemented */
|
||||
|
||||
#define CMD_DEL_ALL_HOST_COMMENTS 20
|
||||
#define CMD_DEL_ALL_SVC_COMMENTS 21
|
||||
|
||||
#define CMD_ENABLE_SVC_NOTIFICATIONS 22
|
||||
#define CMD_DISABLE_SVC_NOTIFICATIONS 23
|
||||
#define CMD_ENABLE_HOST_NOTIFICATIONS 24
|
||||
#define CMD_DISABLE_HOST_NOTIFICATIONS 25
|
||||
#define CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST 26
|
||||
#define CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST 27
|
||||
#define CMD_ENABLE_HOST_SVC_NOTIFICATIONS 28
|
||||
#define CMD_DISABLE_HOST_SVC_NOTIFICATIONS 29
|
||||
|
||||
#define CMD_PROCESS_SERVICE_CHECK_RESULT 30
|
||||
|
||||
#define CMD_SAVE_STATE_INFORMATION 31
|
||||
#define CMD_READ_STATE_INFORMATION 32
|
||||
|
||||
#define CMD_ACKNOWLEDGE_HOST_PROBLEM 33
|
||||
#define CMD_ACKNOWLEDGE_SVC_PROBLEM 34
|
||||
|
||||
#define CMD_START_EXECUTING_SVC_CHECKS 35
|
||||
#define CMD_STOP_EXECUTING_SVC_CHECKS 36
|
||||
|
||||
#define CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS 37
|
||||
#define CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS 38
|
||||
|
||||
#define CMD_ENABLE_PASSIVE_SVC_CHECKS 39
|
||||
#define CMD_DISABLE_PASSIVE_SVC_CHECKS 40
|
||||
|
||||
#define CMD_ENABLE_EVENT_HANDLERS 41
|
||||
#define CMD_DISABLE_EVENT_HANDLERS 42
|
||||
|
||||
#define CMD_ENABLE_HOST_EVENT_HANDLER 43
|
||||
#define CMD_DISABLE_HOST_EVENT_HANDLER 44
|
||||
|
||||
#define CMD_ENABLE_SVC_EVENT_HANDLER 45
|
||||
#define CMD_DISABLE_SVC_EVENT_HANDLER 46
|
||||
|
||||
#define CMD_ENABLE_HOST_CHECK 47
|
||||
#define CMD_DISABLE_HOST_CHECK 48
|
||||
|
||||
#define CMD_START_OBSESSING_OVER_SVC_CHECKS 49
|
||||
#define CMD_STOP_OBSESSING_OVER_SVC_CHECKS 50
|
||||
|
||||
#define CMD_REMOVE_HOST_ACKNOWLEDGEMENT 51
|
||||
#define CMD_REMOVE_SVC_ACKNOWLEDGEMENT 52
|
||||
|
||||
#define CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS 53
|
||||
#define CMD_SCHEDULE_FORCED_SVC_CHECK 54
|
||||
|
||||
#define CMD_SCHEDULE_HOST_DOWNTIME 55
|
||||
#define CMD_SCHEDULE_SVC_DOWNTIME 56
|
||||
|
||||
#define CMD_ENABLE_HOST_FLAP_DETECTION 57
|
||||
#define CMD_DISABLE_HOST_FLAP_DETECTION 58
|
||||
|
||||
#define CMD_ENABLE_SVC_FLAP_DETECTION 59
|
||||
#define CMD_DISABLE_SVC_FLAP_DETECTION 60
|
||||
|
||||
#define CMD_ENABLE_FLAP_DETECTION 61
|
||||
#define CMD_DISABLE_FLAP_DETECTION 62
|
||||
|
||||
#define CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS 63
|
||||
#define CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS 64
|
||||
|
||||
#define CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS 65
|
||||
#define CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS 66
|
||||
|
||||
#define CMD_ENABLE_HOSTGROUP_SVC_CHECKS 67
|
||||
#define CMD_DISABLE_HOSTGROUP_SVC_CHECKS 68
|
||||
|
||||
#define CMD_CANCEL_HOST_DOWNTIME 69 /* not internally implemented */
|
||||
#define CMD_CANCEL_SVC_DOWNTIME 70 /* not internally implemented */
|
||||
|
||||
#define CMD_CANCEL_ACTIVE_HOST_DOWNTIME 71 /* old - no longer used */
|
||||
#define CMD_CANCEL_PENDING_HOST_DOWNTIME 72 /* old - no longer used */
|
||||
|
||||
#define CMD_CANCEL_ACTIVE_SVC_DOWNTIME 73 /* old - no longer used */
|
||||
#define CMD_CANCEL_PENDING_SVC_DOWNTIME 74 /* old - no longer used */
|
||||
|
||||
#define CMD_CANCEL_ACTIVE_HOST_SVC_DOWNTIME 75 /* unimplemented */
|
||||
#define CMD_CANCEL_PENDING_HOST_SVC_DOWNTIME 76 /* unimplemented */
|
||||
|
||||
#define CMD_FLUSH_PENDING_COMMANDS 77
|
||||
|
||||
#define CMD_DEL_HOST_DOWNTIME 78
|
||||
#define CMD_DEL_SVC_DOWNTIME 79
|
||||
|
||||
#define CMD_ENABLE_FAILURE_PREDICTION 80
|
||||
#define CMD_DISABLE_FAILURE_PREDICTION 81
|
||||
|
||||
#define CMD_ENABLE_PERFORMANCE_DATA 82
|
||||
#define CMD_DISABLE_PERFORMANCE_DATA 83
|
||||
|
||||
#define CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME 84
|
||||
#define CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME 85
|
||||
#define CMD_SCHEDULE_HOST_SVC_DOWNTIME 86
|
||||
|
||||
/* new commands in Nagios 2.x found below... */
|
||||
#define CMD_PROCESS_HOST_CHECK_RESULT 87
|
||||
|
||||
#define CMD_START_EXECUTING_HOST_CHECKS 88
|
||||
#define CMD_STOP_EXECUTING_HOST_CHECKS 89
|
||||
|
||||
#define CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS 90
|
||||
#define CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS 91
|
||||
|
||||
#define CMD_ENABLE_PASSIVE_HOST_CHECKS 92
|
||||
#define CMD_DISABLE_PASSIVE_HOST_CHECKS 93
|
||||
|
||||
#define CMD_START_OBSESSING_OVER_HOST_CHECKS 94
|
||||
#define CMD_STOP_OBSESSING_OVER_HOST_CHECKS 95
|
||||
|
||||
#define CMD_SCHEDULE_HOST_CHECK 96
|
||||
#define CMD_SCHEDULE_FORCED_HOST_CHECK 98
|
||||
|
||||
#define CMD_START_OBSESSING_OVER_SVC 99
|
||||
#define CMD_STOP_OBSESSING_OVER_SVC 100
|
||||
|
||||
#define CMD_START_OBSESSING_OVER_HOST 101
|
||||
#define CMD_STOP_OBSESSING_OVER_HOST 102
|
||||
|
||||
#define CMD_ENABLE_HOSTGROUP_HOST_CHECKS 103
|
||||
#define CMD_DISABLE_HOSTGROUP_HOST_CHECKS 104
|
||||
|
||||
#define CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS 105
|
||||
#define CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS 106
|
||||
|
||||
#define CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS 107
|
||||
#define CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS 108
|
||||
|
||||
#define CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS 109
|
||||
#define CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS 110
|
||||
|
||||
#define CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS 111
|
||||
#define CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS 112
|
||||
|
||||
#define CMD_ENABLE_SERVICEGROUP_SVC_CHECKS 113
|
||||
#define CMD_DISABLE_SERVICEGROUP_SVC_CHECKS 114
|
||||
|
||||
#define CMD_ENABLE_SERVICEGROUP_HOST_CHECKS 115
|
||||
#define CMD_DISABLE_SERVICEGROUP_HOST_CHECKS 116
|
||||
|
||||
#define CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS 117
|
||||
#define CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS 118
|
||||
|
||||
#define CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS 119
|
||||
#define CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS 120
|
||||
|
||||
#define CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME 121
|
||||
#define CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME 122
|
||||
|
||||
#define CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER 123
|
||||
#define CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER 124
|
||||
|
||||
#define CMD_CHANGE_HOST_EVENT_HANDLER 125
|
||||
#define CMD_CHANGE_SVC_EVENT_HANDLER 126
|
||||
|
||||
#define CMD_CHANGE_HOST_CHECK_COMMAND 127
|
||||
#define CMD_CHANGE_SVC_CHECK_COMMAND 128
|
||||
|
||||
#define CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL 129
|
||||
#define CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL 130
|
||||
#define CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL 131
|
||||
|
||||
#define CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS 132
|
||||
#define CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS 133
|
||||
|
||||
#define CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME 134
|
||||
|
||||
#define CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS 135
|
||||
#define CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS 136
|
||||
|
||||
#define CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME 137
|
||||
|
||||
#define CMD_ENABLE_SERVICE_FRESHNESS_CHECKS 138
|
||||
#define CMD_DISABLE_SERVICE_FRESHNESS_CHECKS 139
|
||||
|
||||
#define CMD_ENABLE_HOST_FRESHNESS_CHECKS 140
|
||||
#define CMD_DISABLE_HOST_FRESHNESS_CHECKS 141
|
||||
|
||||
#define CMD_SET_HOST_NOTIFICATION_NUMBER 142
|
||||
#define CMD_SET_SVC_NOTIFICATION_NUMBER 143
|
||||
|
||||
/* new commands in Nagios 3.x found below... */
|
||||
#define CMD_CHANGE_HOST_CHECK_TIMEPERIOD 144
|
||||
#define CMD_CHANGE_SVC_CHECK_TIMEPERIOD 145
|
||||
|
||||
#define CMD_PROCESS_FILE 146
|
||||
|
||||
#define CMD_CHANGE_CUSTOM_HOST_VAR 147
|
||||
#define CMD_CHANGE_CUSTOM_SVC_VAR 148
|
||||
#define CMD_CHANGE_CUSTOM_CONTACT_VAR 149
|
||||
|
||||
#define CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS 150
|
||||
#define CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS 151
|
||||
#define CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS 152
|
||||
#define CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS 153
|
||||
|
||||
#define CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS 154
|
||||
#define CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS 155
|
||||
#define CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS 156
|
||||
#define CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS 157
|
||||
|
||||
#define CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL 158
|
||||
|
||||
#define CMD_SEND_CUSTOM_HOST_NOTIFICATION 159
|
||||
#define CMD_SEND_CUSTOM_SVC_NOTIFICATION 160
|
||||
|
||||
#define CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD 161
|
||||
#define CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD 162
|
||||
#define CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD 163
|
||||
#define CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD 164
|
||||
|
||||
#define CMD_CHANGE_HOST_MODATTR 165
|
||||
#define CMD_CHANGE_SVC_MODATTR 166
|
||||
#define CMD_CHANGE_CONTACT_MODATTR 167
|
||||
#define CMD_CHANGE_CONTACT_MODHATTR 168
|
||||
#define CMD_CHANGE_CONTACT_MODSATTR 169
|
||||
|
||||
#define CMD_SYNC_STATE_INFORMATION 170
|
||||
|
||||
#define CMD_DEL_DOWNTIME_BY_HOST_NAME 171
|
||||
#define CMD_DEL_DOWNTIME_BY_HOSTGROUP_NAME 172
|
||||
#define CMD_DEL_DOWNTIME_BY_START_TIME_COMMENT 173
|
||||
|
||||
/* Added for expiring Acknowlwdgements */
|
||||
|
||||
#define CMD_ACKNOWLEDGE_HOST_PROBLEM_EXPIRE 174
|
||||
#define CMD_ACKNOWLEDGE_SVC_PROBLEM_EXPIRE 175
|
||||
|
||||
/* for disabled notifications expiry */
|
||||
#define CMD_DISABLE_NOTIFICATIONS_EXPIRE_TIME 176
|
||||
|
||||
/* custom command introduced in Nagios 3.x */
|
||||
#define CMD_CUSTOM_COMMAND 999
|
||||
|
||||
|
||||
|
||||
/************************ SERVICE CHECK TYPES ****************************/
|
||||
|
||||
#define SERVICE_CHECK_ACTIVE 0 /* Icinga performed the service check */
|
||||
#define SERVICE_CHECK_PASSIVE 1 /* the service check result was submitted by an external source */
|
||||
|
||||
|
||||
/************************** HOST CHECK TYPES *****************************/
|
||||
|
||||
#define HOST_CHECK_ACTIVE 0 /* Icinga performed the host check */
|
||||
#define HOST_CHECK_PASSIVE 1 /* the host check result was submitted by an external source */
|
||||
|
||||
|
||||
/************************ SERVICE STATE TYPES ****************************/
|
||||
|
||||
#define SOFT_STATE 0
|
||||
#define HARD_STATE 1
|
||||
|
||||
|
||||
/************************* SCHEDULED DOWNTIME TYPES **********************/
|
||||
|
||||
#define SERVICE_DOWNTIME 1 /* service downtime */
|
||||
#define HOST_DOWNTIME 2 /* host downtime */
|
||||
#define ANY_DOWNTIME 3 /* host or service downtime */
|
||||
|
||||
|
||||
/************************** NOTIFICATION OPTIONS *************************/
|
||||
|
||||
#define NOTIFICATION_OPTION_NONE 0
|
||||
#define NOTIFICATION_OPTION_BROADCAST 1
|
||||
#define NOTIFICATION_OPTION_FORCED 2
|
||||
#define NOTIFICATION_OPTION_INCREMENT 4
|
||||
|
||||
|
||||
/************************** ACKNOWLEDGEMENT TYPES ************************/
|
||||
|
||||
#define HOST_ACKNOWLEDGEMENT 0
|
||||
#define SERVICE_ACKNOWLEDGEMENT 1
|
||||
|
||||
#define ACKNOWLEDGEMENT_NONE 0
|
||||
#define ACKNOWLEDGEMENT_NORMAL 1
|
||||
#define ACKNOWLEDGEMENT_STICKY 2
|
||||
|
||||
|
||||
/**************************** DEPENDENCY TYPES ***************************/
|
||||
|
||||
#define NOTIFICATION_DEPENDENCY 1
|
||||
#define EXECUTION_DEPENDENCY 2
|
||||
|
||||
|
||||
|
||||
/********************** HOST/SERVICE CHECK OPTIONS ***********************/
|
||||
|
||||
#define CHECK_OPTION_NONE 0 /* no check options */
|
||||
#define CHECK_OPTION_FORCE_EXECUTION 1 /* force execution of a check (ignores disabled services/hosts, invalid timeperiods) */
|
||||
#define CHECK_OPTION_FRESHNESS_CHECK 2 /* this is a freshness check */
|
||||
#define CHECK_OPTION_ORPHAN_CHECK 4 /* this is an orphan check */
|
||||
|
||||
|
||||
/**************************** PROGRAM MODES ******************************/
|
||||
|
||||
#define STANDBY_MODE 0
|
||||
#define ACTIVE_MODE 1
|
||||
|
||||
|
||||
/************************** LOG ROTATION MODES ***************************/
|
||||
|
||||
#define LOG_ROTATION_NONE 0
|
||||
#define LOG_ROTATION_HOURLY 1
|
||||
#define LOG_ROTATION_DAILY 2
|
||||
#define LOG_ROTATION_WEEKLY 3
|
||||
#define LOG_ROTATION_MONTHLY 4
|
||||
|
||||
|
||||
/***************************** LOG VERSIONS ******************************/
|
||||
|
||||
#define LOG_VERSION_1 "1.0"
|
||||
#define LOG_VERSION_2 "2.0"
|
||||
|
||||
|
||||
|
||||
/*************************** CHECK STATISTICS ****************************/
|
||||
|
||||
#define ACTIVE_SCHEDULED_SERVICE_CHECK_STATS 0
|
||||
#define ACTIVE_ONDEMAND_SERVICE_CHECK_STATS 1
|
||||
#define PASSIVE_SERVICE_CHECK_STATS 2
|
||||
#define ACTIVE_SCHEDULED_HOST_CHECK_STATS 3
|
||||
#define ACTIVE_ONDEMAND_HOST_CHECK_STATS 4
|
||||
#define PASSIVE_HOST_CHECK_STATS 5
|
||||
#define ACTIVE_CACHED_HOST_CHECK_STATS 6
|
||||
#define ACTIVE_CACHED_SERVICE_CHECK_STATS 7
|
||||
#define EXTERNAL_COMMAND_STATS 8
|
||||
#define PARALLEL_HOST_CHECK_STATS 9
|
||||
#define SERIAL_HOST_CHECK_STATS 10
|
||||
#define MAX_CHECK_STATS_TYPES 11
|
||||
|
||||
|
||||
/************************* GENERAL DEFINITIONS **************************/
|
||||
|
||||
#define OK 0
|
||||
#define ERROR -2 /* value was changed from -1 so as to not interfere with STATUS_UNKNOWN plugin result */
|
||||
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#elif (TRUE!=1)
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#elif (FALSE!=0)
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
|
||||
/****************** HOST CONFIG FILE READING OPTIONS ********************/
|
||||
|
||||
#define READ_HOSTS 1
|
||||
#define READ_HOSTGROUPS 2
|
||||
#define READ_CONTACTS 4
|
||||
#define READ_CONTACTGROUPS 8
|
||||
#define READ_SERVICES 16
|
||||
#define READ_COMMANDS 32
|
||||
#define READ_TIMEPERIODS 64
|
||||
#define READ_SERVICEESCALATIONS 128
|
||||
#define READ_HOSTGROUPESCALATIONS 256 /* no longer implemented */
|
||||
#define READ_SERVICEDEPENDENCIES 512
|
||||
#define READ_HOSTDEPENDENCIES 1024
|
||||
#define READ_HOSTESCALATIONS 2048
|
||||
#define READ_HOSTEXTINFO 4096
|
||||
#define READ_SERVICEEXTINFO 8192
|
||||
#define READ_SERVICEGROUPS 16384
|
||||
#define READ_MODULES 32768
|
||||
|
||||
#define READ_ALL_OBJECT_DATA READ_HOSTS | READ_HOSTGROUPS | READ_CONTACTS | READ_CONTACTGROUPS | READ_SERVICES | READ_COMMANDS | READ_TIMEPERIODS | READ_SERVICEESCALATIONS | READ_SERVICEDEPENDENCIES | READ_HOSTDEPENDENCIES | READ_HOSTESCALATIONS | READ_HOSTEXTINFO | READ_SERVICEEXTINFO | READ_SERVICEGROUPS | READ_MODULES
|
||||
|
||||
|
||||
/************************** DATE RANGE TYPES ****************************/
|
||||
|
||||
#define DATERANGE_CALENDAR_DATE 0 /* 2008-12-25 */
|
||||
#define DATERANGE_MONTH_DATE 1 /* july 4 (specific month) */
|
||||
#define DATERANGE_MONTH_DAY 2 /* day 21 (generic month) */
|
||||
#define DATERANGE_MONTH_WEEK_DAY 3 /* 3rd thursday (specific month) */
|
||||
#define DATERANGE_WEEK_DAY 4 /* 3rd thursday (generic month) */
|
||||
#define DATERANGE_TYPES 5
|
||||
|
||||
|
||||
/************************** DATE/TIME TYPES *****************************/
|
||||
|
||||
#define LONG_DATE_TIME 0
|
||||
#define SHORT_DATE_TIME 1
|
||||
#define SHORT_DATE 2
|
||||
#define SHORT_TIME 3
|
||||
#define HTTP_DATE_TIME 4 /* time formatted for use in HTTP headers */
|
||||
|
||||
|
||||
/**************************** DATE FORMATS ******************************/
|
||||
|
||||
#define DATE_FORMAT_US 0 /* U.S. (MM-DD-YYYY HH:MM:SS) */
|
||||
#define DATE_FORMAT_EURO 1 /* European (DD-MM-YYYY HH:MM:SS) */
|
||||
#define DATE_FORMAT_ISO8601 2 /* ISO8601 (YYYY-MM-DD HH:MM:SS) */
|
||||
#define DATE_FORMAT_STRICT_ISO8601 3 /* ISO8601 (YYYY-MM-DDTHH:MM:SS) */
|
||||
|
||||
|
||||
/************************** MISC DEFINITIONS ****************************/
|
||||
|
||||
#define MAX_FILENAME_LENGTH 256 /* max length of path/filename that Icinga will process */
|
||||
#define MAX_INPUT_BUFFER 1024 /* size in bytes of max. input buffer (for reading files, misc stuff) */
|
||||
#define MAX_COMMAND_BUFFER 8192 /* max length of raw or processed command line */
|
||||
#define MAX_EXTERNAL_COMMAND_LENGTH 8192 /* max length of an external command */
|
||||
|
||||
#define MAX_DATETIME_LENGTH 48
|
||||
|
||||
/************************* MODIFIED ATTRIBUTES **************************/
|
||||
|
||||
#define MODATTR_NONE 0
|
||||
#define MODATTR_NOTIFICATIONS_ENABLED 1
|
||||
#define MODATTR_ACTIVE_CHECKS_ENABLED 2
|
||||
#define MODATTR_PASSIVE_CHECKS_ENABLED 4
|
||||
#define MODATTR_EVENT_HANDLER_ENABLED 8
|
||||
#define MODATTR_FLAP_DETECTION_ENABLED 16
|
||||
#define MODATTR_FAILURE_PREDICTION_ENABLED 32
|
||||
#define MODATTR_PERFORMANCE_DATA_ENABLED 64
|
||||
#define MODATTR_OBSESSIVE_HANDLER_ENABLED 128
|
||||
#define MODATTR_EVENT_HANDLER_COMMAND 256
|
||||
#define MODATTR_CHECK_COMMAND 512
|
||||
#define MODATTR_NORMAL_CHECK_INTERVAL 1024
|
||||
#define MODATTR_RETRY_CHECK_INTERVAL 2048
|
||||
#define MODATTR_MAX_CHECK_ATTEMPTS 4096
|
||||
#define MODATTR_FRESHNESS_CHECKS_ENABLED 8192
|
||||
#define MODATTR_CHECK_TIMEPERIOD 16384
|
||||
#define MODATTR_CUSTOM_VARIABLE 32768
|
||||
#define MODATTR_NOTIFICATION_TIMEPERIOD 65536
|
||||
|
||||
|
Binary file not shown.
|
@ -0,0 +1,684 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* COMMANDS.C - Extacted comamnd handling from the icinga core, supports testing external
|
||||
* commands without requiring a full running system
|
||||
*
|
||||
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
|
||||
* Copyright (c) 2009-2012 Nagios Core Development Team and Community Contributors
|
||||
* Copyright (c) 2009-2012 Icinga Development Team (http://www.icinga.org)
|
||||
*
|
||||
* License:
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include "common.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
int dummy; /* reduce compiler warnings */
|
||||
/* fix the problem with strtok() skipping empty options between tokens */
|
||||
char *my_strtok(char *buffer, char *tokens) {
|
||||
char *token_position = NULL;
|
||||
char *sequence_head = NULL;
|
||||
static char *my_strtok_buffer = NULL;
|
||||
static char *original_my_strtok_buffer = NULL;
|
||||
|
||||
if (buffer != NULL) {
|
||||
my_free(original_my_strtok_buffer);
|
||||
if ((my_strtok_buffer = (char *)strdup(buffer)) == NULL)
|
||||
return NULL;
|
||||
original_my_strtok_buffer = my_strtok_buffer;
|
||||
}
|
||||
|
||||
sequence_head = my_strtok_buffer;
|
||||
|
||||
if (sequence_head[0] == '\x0')
|
||||
return NULL;
|
||||
|
||||
token_position = strchr(my_strtok_buffer, tokens[0]);
|
||||
|
||||
if (token_position == NULL) {
|
||||
my_strtok_buffer = strchr(my_strtok_buffer, '\x0');
|
||||
return sequence_head;
|
||||
}
|
||||
|
||||
token_position[0] = '\x0';
|
||||
my_strtok_buffer = token_position + 1;
|
||||
|
||||
return sequence_head;
|
||||
}
|
||||
|
||||
/* fixes compiler problems under Solaris, since strsep() isn't included */
|
||||
/* this code is taken from the glibc source */
|
||||
char *my_strsep(char **stringp, const char *delim) {
|
||||
char *begin, *end;
|
||||
|
||||
begin = *stringp;
|
||||
if (begin == NULL)
|
||||
return NULL;
|
||||
|
||||
/* A frequent case is when the delimiter string contains only one
|
||||
* character. Here we don't need to call the expensive `strpbrk'
|
||||
* function and instead work using `strchr'. */
|
||||
if (delim[0] == '\0' || delim[1] == '\0') {
|
||||
char ch = delim[0];
|
||||
|
||||
if (ch == '\0' || begin[0] == '\0')
|
||||
end = NULL;
|
||||
else {
|
||||
if (*begin == ch)
|
||||
end = begin;
|
||||
else
|
||||
end = strchr(begin + 1, ch);
|
||||
}
|
||||
} else {
|
||||
/* find the end of the token. */
|
||||
end = strpbrk(begin, delim);
|
||||
}
|
||||
|
||||
if (end) {
|
||||
/* terminate the token and set *STRINGP past NUL character. */
|
||||
*end++ = '\0';
|
||||
*stringp = end;
|
||||
} else
|
||||
/* no more delimiters; this is the last token. */
|
||||
*stringp = NULL;
|
||||
|
||||
return begin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* strip newline, carriage return, and tab characters from beginning and end of a string */
|
||||
void strip(char *buffer) {
|
||||
register int x;
|
||||
register int y;
|
||||
register int z;
|
||||
|
||||
if (buffer == NULL || buffer[0] == '\x0')
|
||||
return;
|
||||
|
||||
/* strip end of string */
|
||||
y = (int)strlen(buffer);
|
||||
for (x = y - 1; x >= 0; x--) {
|
||||
if (buffer[x] == ' ' || buffer[x] == '\n' || buffer[x] == '\r' || buffer[x] == '\t' || buffer[x] == 13)
|
||||
buffer[x] = '\x0';
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
/* strip beginning of string (by shifting) */
|
||||
y = (int)strlen(buffer);
|
||||
for (x = 0; x < y; x++) {
|
||||
if (buffer[x] == ' ' || buffer[x] == '\n' || buffer[x] == '\r' || buffer[x] == '\t' || buffer[x] == 13)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (x > 0) {
|
||||
for (z = x; z < y; z++)
|
||||
buffer[z-x] = buffer[z];
|
||||
buffer[y-x] = '\x0';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* top-level external command processor */
|
||||
int main(int argv, char **argc) {
|
||||
if(argv < 2) {
|
||||
printf("Not enough arguments!\n");
|
||||
return 1;
|
||||
}
|
||||
char *cmd = argc[1];
|
||||
char *temp_buffer = NULL;
|
||||
char *command_id = NULL;
|
||||
char *args = NULL;
|
||||
time_t entry_time = 0L;
|
||||
int command_type = CMD_NONE;
|
||||
char *temp_ptr = NULL;
|
||||
|
||||
if (cmd == NULL) {
|
||||
printf("No command given\n");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* strip the command of newlines and carriage returns */
|
||||
strip(cmd);
|
||||
|
||||
/* get the command entry time */
|
||||
if ((temp_ptr = my_strtok(cmd, "[")) == NULL) {
|
||||
printf("No entry time given\n");
|
||||
return ERROR;
|
||||
}
|
||||
if ((temp_ptr = my_strtok(NULL, "]")) == NULL) {
|
||||
printf("Missing ] character at entry time\n");
|
||||
return ERROR;
|
||||
}
|
||||
entry_time = (time_t)strtoul(temp_ptr, NULL, 10);
|
||||
|
||||
/* get the command identifier */
|
||||
if ((temp_ptr = my_strtok(NULL, ";")) == NULL) {
|
||||
printf("Missing command identifier\n");
|
||||
return ERROR;
|
||||
}
|
||||
if ((command_id = (char *)strdup(temp_ptr + 1)) == NULL) {
|
||||
printf("Missing command identifier\n");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* get the command arguments */
|
||||
if ((temp_ptr = my_strtok(NULL, "\n")) == NULL)
|
||||
args = (char *)strdup("");
|
||||
else
|
||||
args = (char *)strdup(temp_ptr);
|
||||
|
||||
if (args == NULL) {
|
||||
printf("No arguments given\n");
|
||||
my_free(command_id);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* decide what type of command this is... */
|
||||
|
||||
/**************************/
|
||||
/**** PROCESS COMMANDS ****/
|
||||
/**************************/
|
||||
|
||||
if (!strcmp(command_id, "ENTER_STANDBY_MODE") || !strcmp(command_id, "DISABLE_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "ENTER_ACTIVE_MODE") || !strcmp(command_id, "ENABLE_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_NOTIFICATIONS_EXPIRE_TIME"))
|
||||
command_type = CMD_DISABLE_NOTIFICATIONS_EXPIRE_TIME;
|
||||
|
||||
else if (!strcmp(command_id, "SHUTDOWN_PROGRAM") || !strcmp(command_id, "SHUTDOWN_PROCESS"))
|
||||
command_type = CMD_SHUTDOWN_PROCESS;
|
||||
else if (!strcmp(command_id, "RESTART_PROGRAM") || !strcmp(command_id, "RESTART_PROCESS"))
|
||||
command_type = CMD_RESTART_PROCESS;
|
||||
|
||||
else if (!strcmp(command_id, "SAVE_STATE_INFORMATION"))
|
||||
command_type = CMD_SAVE_STATE_INFORMATION;
|
||||
else if (!strcmp(command_id, "READ_STATE_INFORMATION"))
|
||||
command_type = CMD_READ_STATE_INFORMATION;
|
||||
else if (!strcmp(command_id, "SYNC_STATE_INFORMATION"))
|
||||
command_type = CMD_SYNC_STATE_INFORMATION;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_EVENT_HANDLERS"))
|
||||
command_type = CMD_ENABLE_EVENT_HANDLERS;
|
||||
else if (!strcmp(command_id, "DISABLE_EVENT_HANDLERS"))
|
||||
command_type = CMD_DISABLE_EVENT_HANDLERS;
|
||||
|
||||
else if (!strcmp(command_id, "FLUSH_PENDING_COMMANDS"))
|
||||
command_type = CMD_FLUSH_PENDING_COMMANDS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_FAILURE_PREDICTION"))
|
||||
command_type = CMD_ENABLE_FAILURE_PREDICTION;
|
||||
else if (!strcmp(command_id, "DISABLE_FAILURE_PREDICTION"))
|
||||
command_type = CMD_DISABLE_FAILURE_PREDICTION;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_PERFORMANCE_DATA"))
|
||||
command_type = CMD_ENABLE_PERFORMANCE_DATA;
|
||||
else if (!strcmp(command_id, "DISABLE_PERFORMANCE_DATA"))
|
||||
command_type = CMD_DISABLE_PERFORMANCE_DATA;
|
||||
|
||||
else if (!strcmp(command_id, "START_EXECUTING_HOST_CHECKS"))
|
||||
command_type = CMD_START_EXECUTING_HOST_CHECKS;
|
||||
else if (!strcmp(command_id, "STOP_EXECUTING_HOST_CHECKS"))
|
||||
command_type = CMD_STOP_EXECUTING_HOST_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "START_EXECUTING_SVC_CHECKS"))
|
||||
command_type = CMD_START_EXECUTING_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "STOP_EXECUTING_SVC_CHECKS"))
|
||||
command_type = CMD_STOP_EXECUTING_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "START_ACCEPTING_PASSIVE_HOST_CHECKS"))
|
||||
command_type = CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS;
|
||||
else if (!strcmp(command_id, "STOP_ACCEPTING_PASSIVE_HOST_CHECKS"))
|
||||
command_type = CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "START_ACCEPTING_PASSIVE_SVC_CHECKS"))
|
||||
command_type = CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "STOP_ACCEPTING_PASSIVE_SVC_CHECKS"))
|
||||
command_type = CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "START_OBSESSING_OVER_HOST_CHECKS"))
|
||||
command_type = CMD_START_OBSESSING_OVER_HOST_CHECKS;
|
||||
else if (!strcmp(command_id, "STOP_OBSESSING_OVER_HOST_CHECKS"))
|
||||
command_type = CMD_STOP_OBSESSING_OVER_HOST_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "START_OBSESSING_OVER_SVC_CHECKS"))
|
||||
command_type = CMD_START_OBSESSING_OVER_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "STOP_OBSESSING_OVER_SVC_CHECKS"))
|
||||
command_type = CMD_STOP_OBSESSING_OVER_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_FLAP_DETECTION"))
|
||||
command_type = CMD_ENABLE_FLAP_DETECTION;
|
||||
else if (!strcmp(command_id, "DISABLE_FLAP_DETECTION"))
|
||||
command_type = CMD_DISABLE_FLAP_DETECTION;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_GLOBAL_HOST_EVENT_HANDLER"))
|
||||
command_type = CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER;
|
||||
else if (!strcmp(command_id, "CHANGE_GLOBAL_SVC_EVENT_HANDLER"))
|
||||
command_type = CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SERVICE_FRESHNESS_CHECKS"))
|
||||
command_type = CMD_ENABLE_SERVICE_FRESHNESS_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_SERVICE_FRESHNESS_CHECKS"))
|
||||
command_type = CMD_DISABLE_SERVICE_FRESHNESS_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOST_FRESHNESS_CHECKS"))
|
||||
command_type = CMD_ENABLE_HOST_FRESHNESS_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOST_FRESHNESS_CHECKS"))
|
||||
command_type = CMD_DISABLE_HOST_FRESHNESS_CHECKS;
|
||||
|
||||
|
||||
/*******************************/
|
||||
/**** HOST-RELATED COMMANDS ****/
|
||||
/*******************************/
|
||||
|
||||
else if (!strcmp(command_id, "ADD_HOST_COMMENT"))
|
||||
command_type = CMD_ADD_HOST_COMMENT;
|
||||
else if (!strcmp(command_id, "DEL_HOST_COMMENT"))
|
||||
command_type = CMD_DEL_HOST_COMMENT;
|
||||
else if (!strcmp(command_id, "DEL_ALL_HOST_COMMENTS"))
|
||||
command_type = CMD_DEL_ALL_HOST_COMMENTS;
|
||||
|
||||
else if (!strcmp(command_id, "DELAY_HOST_NOTIFICATION"))
|
||||
command_type = CMD_DELAY_HOST_NOTIFICATION;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_HOST_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_HOST_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST"))
|
||||
command_type = CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST;
|
||||
else if (!strcmp(command_id, "DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST"))
|
||||
command_type = CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOST_AND_CHILD_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOST_AND_CHILD_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOST_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_HOST_SVC_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOST_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_HOST_SVC_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOST_SVC_CHECKS"))
|
||||
command_type = CMD_ENABLE_HOST_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOST_SVC_CHECKS"))
|
||||
command_type = CMD_DISABLE_HOST_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_PASSIVE_HOST_CHECKS"))
|
||||
command_type = CMD_ENABLE_PASSIVE_HOST_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_PASSIVE_HOST_CHECKS"))
|
||||
command_type = CMD_DISABLE_PASSIVE_HOST_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "SCHEDULE_HOST_SVC_CHECKS"))
|
||||
command_type = CMD_SCHEDULE_HOST_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "SCHEDULE_FORCED_HOST_SVC_CHECKS"))
|
||||
command_type = CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ACKNOWLEDGE_HOST_PROBLEM"))
|
||||
command_type = CMD_ACKNOWLEDGE_HOST_PROBLEM;
|
||||
else if (!strcmp(command_id, "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE"))
|
||||
command_type = CMD_ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;
|
||||
else if (!strcmp(command_id, "REMOVE_HOST_ACKNOWLEDGEMENT"))
|
||||
command_type = CMD_REMOVE_HOST_ACKNOWLEDGEMENT;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOST_EVENT_HANDLER"))
|
||||
command_type = CMD_ENABLE_HOST_EVENT_HANDLER;
|
||||
else if (!strcmp(command_id, "DISABLE_HOST_EVENT_HANDLER"))
|
||||
command_type = CMD_DISABLE_HOST_EVENT_HANDLER;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOST_CHECK"))
|
||||
command_type = CMD_ENABLE_HOST_CHECK;
|
||||
else if (!strcmp(command_id, "DISABLE_HOST_CHECK"))
|
||||
command_type = CMD_DISABLE_HOST_CHECK;
|
||||
|
||||
else if (!strcmp(command_id, "SCHEDULE_HOST_CHECK"))
|
||||
command_type = CMD_SCHEDULE_HOST_CHECK;
|
||||
else if (!strcmp(command_id, "SCHEDULE_FORCED_HOST_CHECK"))
|
||||
command_type = CMD_SCHEDULE_FORCED_HOST_CHECK;
|
||||
|
||||
else if (!strcmp(command_id, "SCHEDULE_HOST_DOWNTIME"))
|
||||
command_type = CMD_SCHEDULE_HOST_DOWNTIME;
|
||||
else if (!strcmp(command_id, "SCHEDULE_HOST_SVC_DOWNTIME"))
|
||||
command_type = CMD_SCHEDULE_HOST_SVC_DOWNTIME;
|
||||
else if (!strcmp(command_id, "DEL_HOST_DOWNTIME"))
|
||||
command_type = CMD_DEL_HOST_DOWNTIME;
|
||||
else if (!strcmp(command_id, "DEL_DOWNTIME_BY_HOST_NAME"))
|
||||
command_type = CMD_DEL_DOWNTIME_BY_HOST_NAME;
|
||||
else if (!strcmp(command_id, "DEL_DOWNTIME_BY_HOSTGROUP_NAME"))
|
||||
command_type = CMD_DEL_DOWNTIME_BY_HOSTGROUP_NAME;
|
||||
|
||||
else if (!strcmp(command_id, "DEL_DOWNTIME_BY_START_TIME_COMMENT"))
|
||||
command_type = CMD_DEL_DOWNTIME_BY_START_TIME_COMMENT;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOST_FLAP_DETECTION"))
|
||||
command_type = CMD_ENABLE_HOST_FLAP_DETECTION;
|
||||
else if (!strcmp(command_id, "DISABLE_HOST_FLAP_DETECTION"))
|
||||
command_type = CMD_DISABLE_HOST_FLAP_DETECTION;
|
||||
|
||||
else if (!strcmp(command_id, "START_OBSESSING_OVER_HOST"))
|
||||
command_type = CMD_START_OBSESSING_OVER_HOST;
|
||||
else if (!strcmp(command_id, "STOP_OBSESSING_OVER_HOST"))
|
||||
command_type = CMD_STOP_OBSESSING_OVER_HOST;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_HOST_EVENT_HANDLER"))
|
||||
command_type = CMD_CHANGE_HOST_EVENT_HANDLER;
|
||||
else if (!strcmp(command_id, "CHANGE_HOST_CHECK_COMMAND"))
|
||||
command_type = CMD_CHANGE_HOST_CHECK_COMMAND;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_NORMAL_HOST_CHECK_INTERVAL"))
|
||||
command_type = CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL;
|
||||
else if (!strcmp(command_id, "CHANGE_RETRY_HOST_CHECK_INTERVAL"))
|
||||
command_type = CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_MAX_HOST_CHECK_ATTEMPTS"))
|
||||
command_type = CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS;
|
||||
|
||||
else if (!strcmp(command_id, "SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME"))
|
||||
command_type = CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;
|
||||
|
||||
else if (!strcmp(command_id, "SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME"))
|
||||
command_type = CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;
|
||||
|
||||
else if (!strcmp(command_id, "SET_HOST_NOTIFICATION_NUMBER"))
|
||||
command_type = CMD_SET_HOST_NOTIFICATION_NUMBER;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_HOST_CHECK_TIMEPERIOD"))
|
||||
command_type = CMD_CHANGE_HOST_CHECK_TIMEPERIOD;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_CUSTOM_HOST_VAR"))
|
||||
command_type = CMD_CHANGE_CUSTOM_HOST_VAR;
|
||||
|
||||
else if (!strcmp(command_id, "SEND_CUSTOM_HOST_NOTIFICATION"))
|
||||
command_type = CMD_SEND_CUSTOM_HOST_NOTIFICATION;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_HOST_NOTIFICATION_TIMEPERIOD"))
|
||||
command_type = CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_HOST_MODATTR"))
|
||||
command_type = CMD_CHANGE_HOST_MODATTR;
|
||||
|
||||
|
||||
/************************************/
|
||||
/**** HOSTGROUP-RELATED COMMANDS ****/
|
||||
/************************************/
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOSTGROUP_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOSTGROUP_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOSTGROUP_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOSTGROUP_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOSTGROUP_HOST_CHECKS"))
|
||||
command_type = CMD_ENABLE_HOSTGROUP_HOST_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOSTGROUP_HOST_CHECKS"))
|
||||
command_type = CMD_DISABLE_HOSTGROUP_HOST_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS"))
|
||||
command_type = CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS"))
|
||||
command_type = CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOSTGROUP_SVC_CHECKS"))
|
||||
command_type = CMD_ENABLE_HOSTGROUP_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOSTGROUP_SVC_CHECKS"))
|
||||
command_type = CMD_DISABLE_HOSTGROUP_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS"))
|
||||
command_type = CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS"))
|
||||
command_type = CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "SCHEDULE_HOSTGROUP_HOST_DOWNTIME"))
|
||||
command_type = CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME;
|
||||
else if (!strcmp(command_id, "SCHEDULE_HOSTGROUP_SVC_DOWNTIME"))
|
||||
command_type = CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME;
|
||||
|
||||
|
||||
/**********************************/
|
||||
/**** SERVICE-RELATED COMMANDS ****/
|
||||
/**********************************/
|
||||
|
||||
else if (!strcmp(command_id, "ADD_SVC_COMMENT"))
|
||||
command_type = CMD_ADD_SVC_COMMENT;
|
||||
else if (!strcmp(command_id, "DEL_SVC_COMMENT"))
|
||||
command_type = CMD_DEL_SVC_COMMENT;
|
||||
else if (!strcmp(command_id, "DEL_ALL_SVC_COMMENTS"))
|
||||
command_type = CMD_DEL_ALL_SVC_COMMENTS;
|
||||
|
||||
else if (!strcmp(command_id, "SCHEDULE_SVC_CHECK"))
|
||||
command_type = CMD_SCHEDULE_SVC_CHECK;
|
||||
else if (!strcmp(command_id, "SCHEDULE_FORCED_SVC_CHECK"))
|
||||
command_type = CMD_SCHEDULE_FORCED_SVC_CHECK;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SVC_CHECK"))
|
||||
command_type = CMD_ENABLE_SVC_CHECK;
|
||||
else if (!strcmp(command_id, "DISABLE_SVC_CHECK"))
|
||||
command_type = CMD_DISABLE_SVC_CHECK;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_PASSIVE_SVC_CHECKS"))
|
||||
command_type = CMD_ENABLE_PASSIVE_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_PASSIVE_SVC_CHECKS"))
|
||||
command_type = CMD_DISABLE_PASSIVE_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "DELAY_SVC_NOTIFICATION"))
|
||||
command_type = CMD_DELAY_SVC_NOTIFICATION;
|
||||
else if (!strcmp(command_id, "ENABLE_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_SVC_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_SVC_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "PROCESS_SERVICE_CHECK_RESULT"))
|
||||
command_type = CMD_PROCESS_SERVICE_CHECK_RESULT;
|
||||
else if (!strcmp(command_id, "PROCESS_HOST_CHECK_RESULT"))
|
||||
command_type = CMD_PROCESS_HOST_CHECK_RESULT;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SVC_EVENT_HANDLER"))
|
||||
command_type = CMD_ENABLE_SVC_EVENT_HANDLER;
|
||||
else if (!strcmp(command_id, "DISABLE_SVC_EVENT_HANDLER"))
|
||||
command_type = CMD_DISABLE_SVC_EVENT_HANDLER;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SVC_FLAP_DETECTION"))
|
||||
command_type = CMD_ENABLE_SVC_FLAP_DETECTION;
|
||||
else if (!strcmp(command_id, "DISABLE_SVC_FLAP_DETECTION"))
|
||||
command_type = CMD_DISABLE_SVC_FLAP_DETECTION;
|
||||
|
||||
else if (!strcmp(command_id, "SCHEDULE_SVC_DOWNTIME"))
|
||||
command_type = CMD_SCHEDULE_SVC_DOWNTIME;
|
||||
else if (!strcmp(command_id, "DEL_SVC_DOWNTIME"))
|
||||
command_type = CMD_DEL_SVC_DOWNTIME;
|
||||
|
||||
else if (!strcmp(command_id, "ACKNOWLEDGE_SVC_PROBLEM"))
|
||||
command_type = CMD_ACKNOWLEDGE_SVC_PROBLEM;
|
||||
else if (!strcmp(command_id, "ACKNOWLEDGE_SVC_PROBLEM_EXPIRE"))
|
||||
command_type = CMD_ACKNOWLEDGE_SVC_PROBLEM_EXPIRE;
|
||||
else if (!strcmp(command_id, "REMOVE_SVC_ACKNOWLEDGEMENT"))
|
||||
command_type = CMD_REMOVE_SVC_ACKNOWLEDGEMENT;
|
||||
|
||||
else if (!strcmp(command_id, "START_OBSESSING_OVER_SVC"))
|
||||
command_type = CMD_START_OBSESSING_OVER_SVC;
|
||||
else if (!strcmp(command_id, "STOP_OBSESSING_OVER_SVC"))
|
||||
command_type = CMD_STOP_OBSESSING_OVER_SVC;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_SVC_EVENT_HANDLER"))
|
||||
command_type = CMD_CHANGE_SVC_EVENT_HANDLER;
|
||||
else if (!strcmp(command_id, "CHANGE_SVC_CHECK_COMMAND"))
|
||||
command_type = CMD_CHANGE_SVC_CHECK_COMMAND;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_NORMAL_SVC_CHECK_INTERVAL"))
|
||||
command_type = CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL;
|
||||
else if (!strcmp(command_id, "CHANGE_RETRY_SVC_CHECK_INTERVAL"))
|
||||
command_type = CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_MAX_SVC_CHECK_ATTEMPTS"))
|
||||
command_type = CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS;
|
||||
|
||||
else if (!strcmp(command_id, "SET_SVC_NOTIFICATION_NUMBER"))
|
||||
command_type = CMD_SET_SVC_NOTIFICATION_NUMBER;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_SVC_CHECK_TIMEPERIOD"))
|
||||
command_type = CMD_CHANGE_SVC_CHECK_TIMEPERIOD;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_CUSTOM_SVC_VAR"))
|
||||
command_type = CMD_CHANGE_CUSTOM_SVC_VAR;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_CUSTOM_CONTACT_VAR"))
|
||||
command_type = CMD_CHANGE_CUSTOM_CONTACT_VAR;
|
||||
|
||||
else if (!strcmp(command_id, "SEND_CUSTOM_SVC_NOTIFICATION"))
|
||||
command_type = CMD_SEND_CUSTOM_SVC_NOTIFICATION;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_SVC_NOTIFICATION_TIMEPERIOD"))
|
||||
command_type = CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_SVC_MODATTR"))
|
||||
command_type = CMD_CHANGE_SVC_MODATTR;
|
||||
|
||||
|
||||
/***************************************/
|
||||
/**** SERVICEGROUP-RELATED COMMANDS ****/
|
||||
/***************************************/
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SERVICEGROUP_HOST_CHECKS"))
|
||||
command_type = CMD_ENABLE_SERVICEGROUP_HOST_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_SERVICEGROUP_HOST_CHECKS"))
|
||||
command_type = CMD_DISABLE_SERVICEGROUP_HOST_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS"))
|
||||
command_type = CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS"))
|
||||
command_type = CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SERVICEGROUP_SVC_CHECKS"))
|
||||
command_type = CMD_ENABLE_SERVICEGROUP_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_SERVICEGROUP_SVC_CHECKS"))
|
||||
command_type = CMD_DISABLE_SERVICEGROUP_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS"))
|
||||
command_type = CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;
|
||||
else if (!strcmp(command_id, "DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS"))
|
||||
command_type = CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;
|
||||
|
||||
else if (!strcmp(command_id, "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME"))
|
||||
command_type = CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;
|
||||
else if (!strcmp(command_id, "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME"))
|
||||
command_type = CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;
|
||||
|
||||
|
||||
/**********************************/
|
||||
/**** CONTACT-RELATED COMMANDS ****/
|
||||
/**********************************/
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_CONTACT_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_CONTACT_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_CONTACT_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_CONTACT_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD"))
|
||||
command_type = CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD"))
|
||||
command_type = CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD;
|
||||
|
||||
else if (!strcmp(command_id, "CHANGE_CONTACT_MODATTR"))
|
||||
command_type = CMD_CHANGE_CONTACT_MODATTR;
|
||||
else if (!strcmp(command_id, "CHANGE_CONTACT_MODHATTR"))
|
||||
command_type = CMD_CHANGE_CONTACT_MODHATTR;
|
||||
else if (!strcmp(command_id, "CHANGE_CONTACT_MODSATTR"))
|
||||
command_type = CMD_CHANGE_CONTACT_MODSATTR;
|
||||
|
||||
/***************************************/
|
||||
/**** CONTACTGROUP-RELATED COMMANDS ****/
|
||||
/***************************************/
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS;
|
||||
|
||||
else if (!strcmp(command_id, "ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS;
|
||||
else if (!strcmp(command_id, "DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS"))
|
||||
command_type = CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS;
|
||||
|
||||
|
||||
/**************************/
|
||||
/****** MISC COMMANDS *****/
|
||||
/**************************/
|
||||
|
||||
else if (!strcmp(command_id, "PROCESS_FILE"))
|
||||
command_type = CMD_PROCESS_FILE;
|
||||
|
||||
|
||||
|
||||
/****************************/
|
||||
/****** CUSTOM COMMANDS *****/
|
||||
/****************************/
|
||||
|
||||
else if (command_id[0] == '_')
|
||||
command_type = CMD_CUSTOM_COMMAND;
|
||||
|
||||
|
||||
|
||||
/**** UNKNOWN COMMAND ****/
|
||||
else {
|
||||
/* free memory */
|
||||
printf("UNKNOWN COMMAND: %s;%s\n", command_id, args);
|
||||
my_free(command_id);
|
||||
my_free(args);
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* log the external command */
|
||||
printf("%s;%s\n", command_id, args);
|
||||
my_free(temp_buffer);
|
||||
|
||||
my_free(command_id);
|
||||
my_free(args);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* SHARED.H - Include file for shared functions and structs
|
||||
*
|
||||
* Copyright (c) 2010-2011 Nagios Core Development Team and Community Contributors
|
||||
* Copyright (c) 2010-2011 Icinga Development Team (http://www.icinga.org)
|
||||
*
|
||||
* License:
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef INCLUDE__shared_h__
|
||||
#define INCLUDE__shared_h__
|
||||
|
||||
#include <time.h>
|
||||
/* mmapfile structure - used for reading files via mmap() */
|
||||
typedef struct mmapfile_struct {
|
||||
char *path;
|
||||
int mode;
|
||||
int fd;
|
||||
unsigned long file_size;
|
||||
unsigned long current_position;
|
||||
unsigned long current_line;
|
||||
void *mmap_buf;
|
||||
} mmapfile;
|
||||
|
||||
/* only usable on compile-time initialized arrays, for obvious reasons */
|
||||
#define ARRAY_SIZE(ary) (sizeof(ary) / sizeof(ary[0]))
|
||||
|
||||
extern char *my_strtok(char *buffer, char *tokens);
|
||||
extern char *my_strsep(char **stringp, const char *delim);
|
||||
extern mmapfile *mmap_fopen(char *filename);
|
||||
extern int mmap_fclose(mmapfile *temp_mmapfile);
|
||||
extern char *mmap_fgets(mmapfile *temp_mmapfile);
|
||||
extern char *mmap_fgets_multiline(mmapfile * temp_mmapfile);
|
||||
extern void strip(char *buffer);
|
||||
extern int hashfunc(const char *name1, const char *name2, int hashslots);
|
||||
extern int compare_hashdata(const char *val1a, const char *val1b, const char *val2a,
|
||||
const char *val2b);
|
||||
extern void get_datetime_string(time_t *raw_time, char *buffer,
|
||||
int buffer_length, int type);
|
||||
extern void get_time_breakdown(unsigned long raw_time, int *days, int *hours,
|
||||
int *minutes, int *seconds);
|
||||
#endif
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
/**
|
||||
*
|
||||
* Test class for Bootstrap
|
||||
* Created Thu, 07 Feb 2013 10:07:13 +0000
|
||||
*
|
||||
**/
|
||||
class BootstrapTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::AddModule()
|
||||
*
|
||||
**/
|
||||
public function testAddModule()
|
||||
{
|
||||
$this->markTestIncomplete('testAddModule is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::GetApplicationDir()
|
||||
*
|
||||
**/
|
||||
public function testGetApplicationDir()
|
||||
{
|
||||
$this->markTestIncomplete('testGetApplicationDir is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::GetModuleDir()
|
||||
*
|
||||
**/
|
||||
public function testGetModuleDir()
|
||||
{
|
||||
$this->markTestIncomplete('testGetModuleDir is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::HasModule()
|
||||
*
|
||||
**/
|
||||
public function testHasModule()
|
||||
{
|
||||
$this->markTestIncomplete('testHasModule is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::IsLegacy()
|
||||
*
|
||||
**/
|
||||
public function testIsLegacy()
|
||||
{
|
||||
$this->markTestIncomplete('testIsLegacy is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::IsRunningOnCli()
|
||||
*
|
||||
**/
|
||||
public function testIsRunningOnCli()
|
||||
{
|
||||
$this->markTestIncomplete('testIsRunningOnCli is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::GetLecacyBasedir()
|
||||
*
|
||||
**/
|
||||
public function testGetLecacyBasedir()
|
||||
{
|
||||
$this->markTestIncomplete('testGetLecacyBasedir is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::Dispatch()
|
||||
*
|
||||
**/
|
||||
public function testDispatch()
|
||||
{
|
||||
$this->markTestIncomplete('testDispatch is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::Cli()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testCli()
|
||||
{
|
||||
$this->markTestIncomplete('testCli is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::ForIcingaWeb1x()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testForIcingaWeb1x()
|
||||
{
|
||||
$this->markTestIncomplete('testForIcingaWeb1x is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::Web()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testWeb()
|
||||
{
|
||||
$this->markTestIncomplete('testWeb is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::Embedded()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testEmbedded()
|
||||
{
|
||||
$this->markTestIncomplete('testEmbedded is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Bootstrap::GetInstance()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->markTestIncomplete('testGetInstance is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
/**
|
||||
*
|
||||
* Test class for Config
|
||||
* Created Thu, 07 Feb 2013 10:07:13 +0000
|
||||
*
|
||||
**/
|
||||
class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Config::ListAll()
|
||||
*
|
||||
**/
|
||||
public function testListAll()
|
||||
{
|
||||
$this->markTestIncomplete('testListAll is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Config::GetConfigDir()
|
||||
*
|
||||
**/
|
||||
public function testGetConfigDir()
|
||||
{
|
||||
$this->markTestIncomplete('testGetConfigDir is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Config::__get()
|
||||
*
|
||||
**/
|
||||
public function test__get()
|
||||
{
|
||||
$this->markTestIncomplete('test__get is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Config::GetInstance()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->markTestIncomplete('testGetInstance is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
/**
|
||||
*
|
||||
* Test class for Loader
|
||||
* Created Thu, 07 Feb 2013 10:07:13 +0000
|
||||
*
|
||||
**/
|
||||
class LoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Loader::SetModuleDir()
|
||||
*
|
||||
**/
|
||||
public function testSetModuleDir()
|
||||
{
|
||||
$this->markTestIncomplete('testSetModuleDir is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Loader::AddModule()
|
||||
*
|
||||
**/
|
||||
public function testAddModule()
|
||||
{
|
||||
$this->markTestIncomplete('testAddModule is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Loader::LoadClass()
|
||||
*
|
||||
**/
|
||||
public function testLoadClass()
|
||||
{
|
||||
$this->markTestIncomplete('testLoadClass is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Loader::Register()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testRegister()
|
||||
{
|
||||
$this->markTestIncomplete('testRegister is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Loader::GetInstance()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->markTestIncomplete('testGetInstance is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
|
||||
require_once("Zend/Log.php");
|
||||
require_once("Zend/Config.php");
|
||||
require_once("Zend/Log/Writer/Mock.php");
|
||||
require_once("Zend/Log/Writer/Null.php");
|
||||
require_once("Zend/Log/Filter/Priority.php");
|
||||
|
||||
require_once("../library/Icinga/Application/Logger.php");
|
||||
require_once("../library/Icinga/Exception/ConfigurationError.php");
|
||||
|
||||
use \Icinga\Application\Logger as Logger;
|
||||
/**
|
||||
*
|
||||
* Test class for Logger
|
||||
* Created Thu, 07 Feb 2013 10:07:13 +0000
|
||||
*
|
||||
**/
|
||||
class LoggerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testOverwrite() {
|
||||
$cfg1 = new \Zend_Config(array(
|
||||
"debug" => array("enable" => 0),
|
||||
"type" => "mock",
|
||||
"target" => "target2"
|
||||
));
|
||||
$cfg2 = new \Zend_Config(array(
|
||||
"debug" => array(
|
||||
"enable" => 1,
|
||||
"type"=>"mock",
|
||||
"target"=>"target3"
|
||||
),
|
||||
"type" => "mock",
|
||||
"target" => "target4"
|
||||
));
|
||||
|
||||
$logger = new Logger($cfg1);
|
||||
$writers = $logger->getWriters();
|
||||
$this->assertEquals(1,count($writers));
|
||||
|
||||
$logger = new Logger($cfg1);
|
||||
$writers2 = $logger->getWriters();
|
||||
$this->assertEquals(1,count($writers));
|
||||
$this->assertNotEquals($writers[0],$writers2[0]);
|
||||
|
||||
$logger = new Logger($cfg2);
|
||||
$writers2 = $logger->getWriters();
|
||||
$this->assertEquals(2,count($writers2));
|
||||
}
|
||||
|
||||
|
||||
public function testFormatMessage() {
|
||||
$message = Logger::formatMessage(array("Testmessage"));
|
||||
$this->assertEquals("Testmessage",$message);
|
||||
|
||||
$message = Logger::formatMessage(array("Testmessage %s %s","test1","test2"));
|
||||
$this->assertEquals("Testmessage test1 test2",$message);
|
||||
|
||||
$message = Logger::formatMessage(array("Testmessage %s",array("test1","test2")));
|
||||
$this->assertEquals("Testmessage ".json_encode(array("test1","test2")),$message);
|
||||
}
|
||||
|
||||
|
||||
public function testLoggingOutput() {
|
||||
$cfg1 = new \Zend_Config(array(
|
||||
"debug" => array("enable" => 0),
|
||||
"type" => "mock",
|
||||
"target" => "target2"
|
||||
));
|
||||
Logger::reset();
|
||||
$logger = Logger::create($cfg1);
|
||||
$writers = $logger->getWriters();
|
||||
|
||||
$logger->warn("Warning");
|
||||
$logger->error("Error");
|
||||
$logger->info("Info");
|
||||
$logger->debug("Debug");
|
||||
|
||||
$writer = $writers[0];
|
||||
$this->assertEquals(2,count($writer->events));
|
||||
$this->assertEquals($writer->events[0]["message"],"Warning");
|
||||
$this->assertEquals($writer->events[1]["message"],"Error");
|
||||
Logger::reset();
|
||||
}
|
||||
|
||||
public function testLogQueuing() {
|
||||
$cfg1 = new \Zend_Config(array(
|
||||
"debug" => array("enable" => 0),
|
||||
"type" => "mock",
|
||||
"target" => "target2"
|
||||
));
|
||||
|
||||
Logger::reset();
|
||||
Logger::warn("Warning");
|
||||
Logger::error("Error");
|
||||
Logger::info("Info");
|
||||
Logger::debug("Debug");
|
||||
|
||||
$logger = Logger::create($cfg1);
|
||||
$writers = $logger->getWriters();
|
||||
$writer = $writers[0];
|
||||
|
||||
$this->assertEquals(2,count($writer->events));
|
||||
$this->assertEquals($writer->events[0]["message"],"Warning");
|
||||
$this->assertEquals($writer->events[1]["message"],"Error");
|
||||
Logger::reset();
|
||||
}
|
||||
|
||||
public function testDebugLogErrorCatching()
|
||||
{
|
||||
$cfg1 = new \Zend_Config(array(
|
||||
"debug" => array(
|
||||
"enable" => 1,
|
||||
"type" => 'Invalid',
|
||||
"target" => "..."
|
||||
),
|
||||
"type" => "mock",
|
||||
"target" => "target2"
|
||||
));
|
||||
Logger::reset();
|
||||
$logger = Logger::create($cfg1);
|
||||
$writers = $logger->getWriters();
|
||||
$this->assertEquals(1,count($writers));
|
||||
$this->assertEquals(1,count($writers[0]->events));
|
||||
$exceptionStart = "Could not create debug log:";
|
||||
$this->assertEquals(substr($writers[0]->events[0]["message"],0,strlen($exceptionStart)),$exceptionStart);
|
||||
Logger::reset();
|
||||
}
|
||||
/**
|
||||
* @expectedException \Icinga\Exception\ConfigurationError
|
||||
*/
|
||||
public function testGeneralLogException() {
|
||||
$cfg1 = new \Zend_Config(array(
|
||||
"debug" => array(
|
||||
"enable" => 0,
|
||||
"type" => 'Invalid',
|
||||
"target" => "..."
|
||||
),
|
||||
"type" => "invalid",
|
||||
"target" => "target2"
|
||||
|
||||
));
|
||||
Logger::reset();
|
||||
$logger = Logger::create($cfg1);
|
||||
|
||||
Logger::reset();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
/**
|
||||
*
|
||||
* Test class for Session
|
||||
* Created Thu, 07 Feb 2013 10:07:13 +0000
|
||||
*
|
||||
**/
|
||||
class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Session::GetInstance()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->markTestIncomplete('testGetInstance is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Backend;
|
||||
/**
|
||||
*
|
||||
* Test class for Combo
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class ComboTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Combo::Init()
|
||||
*
|
||||
**/
|
||||
public function testInit()
|
||||
{
|
||||
$this->markTestIncomplete('testInit is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Combo::ListServices()
|
||||
*
|
||||
**/
|
||||
public function testListServices()
|
||||
{
|
||||
$this->markTestIncomplete('testListServices is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Backend;
|
||||
/**
|
||||
*
|
||||
* Test class for Ido
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class IdoTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Ido::Init()
|
||||
*
|
||||
**/
|
||||
public function testInit()
|
||||
{
|
||||
$this->markTestIncomplete('testInit is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Ido::GetSummary()
|
||||
*
|
||||
**/
|
||||
public function testGetSummary()
|
||||
{
|
||||
$this->markTestIncomplete('testGetSummary is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Ido::ListServices()
|
||||
*
|
||||
**/
|
||||
public function testListServices()
|
||||
{
|
||||
$this->markTestIncomplete('testListServices is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Backend;
|
||||
/**
|
||||
*
|
||||
* Test class for Livestatus
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class LivestatusTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Livestatus::Init()
|
||||
*
|
||||
**/
|
||||
public function testInit()
|
||||
{
|
||||
$this->markTestIncomplete('testInit is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Livestatus::Summary()
|
||||
*
|
||||
**/
|
||||
public function testSummary()
|
||||
{
|
||||
$this->markTestIncomplete('testSummary is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Livestatus::ListServices()
|
||||
*
|
||||
**/
|
||||
public function testListServices()
|
||||
{
|
||||
$this->markTestIncomplete('testListServices is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Backend;
|
||||
/**
|
||||
*
|
||||
* Test class for Monitoringobjectlist
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class MonitoringobjectlistTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for MonitoringObjectList::Current()
|
||||
*
|
||||
**/
|
||||
public function testCurrent()
|
||||
{
|
||||
$this->markTestIncomplete('testCurrent is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for MonitoringObjectList::Next()
|
||||
*
|
||||
**/
|
||||
public function testNext()
|
||||
{
|
||||
$this->markTestIncomplete('testNext is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for MonitoringObjectList::Key()
|
||||
*
|
||||
**/
|
||||
public function testKey()
|
||||
{
|
||||
$this->markTestIncomplete('testKey is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for MonitoringObjectList::Valid()
|
||||
*
|
||||
**/
|
||||
public function testValid()
|
||||
{
|
||||
$this->markTestIncomplete('testValid is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for MonitoringObjectList::Rewind()
|
||||
*
|
||||
**/
|
||||
public function testRewind()
|
||||
{
|
||||
$this->markTestIncomplete('testRewind is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for MonitoringObjectList::__isset()
|
||||
*
|
||||
**/
|
||||
public function test__isset()
|
||||
{
|
||||
$this->markTestIncomplete('test__isset is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Backend\Statusdat;
|
||||
use Tests\Icinga\Protocol\Statusdat\ReaderMock as ReaderMock;
|
||||
|
||||
require_once("./library/Icinga/Protocol/Statusdat/ReaderMock.php");
|
||||
require_once("../library/Icinga/Backend/Query.php");
|
||||
require_once("../library/Icinga/Backend/Criteria/Order.php");
|
||||
require_once("../library/Icinga/Backend/AbstractBackend.php");
|
||||
require_once("../library/Icinga/Backend/Statusdat/Query.php");
|
||||
require_once("../library/Icinga/Backend/Statusdat/GroupsummaryQuery.php");
|
||||
require_once("../library/Icinga/Backend/Statusdat/ServicegroupsummaryQuery.php");
|
||||
|
||||
class BackendMock extends \Icinga\Backend\AbstractBackend{
|
||||
public $reader;
|
||||
|
||||
public function select() {
|
||||
return $this;
|
||||
}
|
||||
public function setReader($reader) {
|
||||
$this->reader = $reader;
|
||||
}
|
||||
|
||||
public function getReader() {
|
||||
return $this->reader;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Servicegroupsummaryquery
|
||||
* Created Mon, 18 Feb 2013 14:33:21 +0000
|
||||
*
|
||||
**/
|
||||
class ServicegroupsummaryqueryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testGroupByProblemType()
|
||||
{
|
||||
$backend = new BackendMock();
|
||||
$backend->setReader($this->getTestDataset());
|
||||
$q = new \Icinga\Backend\Statusdat\ServicegroupsummaryQuery($backend);
|
||||
$indices = array(
|
||||
"service" => array(
|
||||
"hosta;service1", "hosta;service2", "hosta;service3",
|
||||
"hostb;service1", "hostb;service2", "hostb;service3", "hostb;service4"
|
||||
)
|
||||
);
|
||||
$this->assertEquals(array(
|
||||
(object) array(
|
||||
"servicegroup_name" => "sv1",
|
||||
'ok' => 1,
|
||||
'critical' => 1,
|
||||
'critical_dt' => 0,
|
||||
'critical_ack' => 1,
|
||||
'unknown' => 0,
|
||||
'unknown_dt' => 0,
|
||||
'unknown_ack' => 0,
|
||||
'warning' => 0,
|
||||
'warning_dt' => 1,
|
||||
'warning_ack' => 2
|
||||
),
|
||||
(object) array(
|
||||
"servicegroup_name" => "sv2",
|
||||
'ok' => 0,
|
||||
'critical' => 0,
|
||||
'critical_dt' => 0,
|
||||
'critical_ack' => 1,
|
||||
'unknown' => 0,
|
||||
'unknown_dt' => 0,
|
||||
'unknown_ack' => 0,
|
||||
'warning' => 1,
|
||||
'warning_dt' => 0,
|
||||
'warning_ack' => 2
|
||||
)
|
||||
),$q->groupByProblemType($indices));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function getTestDataset()
|
||||
{
|
||||
return new ReaderMock(array(
|
||||
"host" => array(
|
||||
"hosta" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"numeric_val" => 0,
|
||||
"services" => array(0, 1, 2)
|
||||
),
|
||||
"hostb" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"numeric_val" => 0,
|
||||
"services" => array(3, 4, 5)
|
||||
)
|
||||
),
|
||||
"service" => array(
|
||||
"hosta;service1" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"service_description" => "service1",
|
||||
"group" => array(
|
||||
"sv1"
|
||||
),
|
||||
"status" => (object) array(
|
||||
"current_state" => 0,
|
||||
"problem_has_been_acknowledged" => 0
|
||||
|
||||
)
|
||||
),
|
||||
"hosta;service2" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"service_description" => "service2",
|
||||
"group" => array(
|
||||
"sv1"
|
||||
),
|
||||
"status" => (object) array(
|
||||
"current_state" => 1,
|
||||
"downtime" => array("..."),
|
||||
"problem_has_been_acknowledged" => 0
|
||||
)
|
||||
),
|
||||
"hosta;service3" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"service_description" => "service3",
|
||||
"group" => array(
|
||||
"sv1"
|
||||
),
|
||||
"status" => (object) array(
|
||||
"current_state" => 2,
|
||||
"problem_has_been_acknowledged" => 0
|
||||
)
|
||||
),
|
||||
"hostb;service1" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service1",
|
||||
"group" => array(
|
||||
"sv2"
|
||||
),
|
||||
"status" => (object) array(
|
||||
"current_state" => 1,
|
||||
"problem_has_been_acknowledged" => 0
|
||||
)
|
||||
),
|
||||
"hostb;service2" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service2",
|
||||
"group" => array(
|
||||
"sv2","sv1"
|
||||
),
|
||||
"status" => (object) array(
|
||||
"current_state" => 2,
|
||||
"problem_has_been_acknowledged" => 1
|
||||
)
|
||||
),
|
||||
"hostb;service3" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service3",
|
||||
"group" => array(
|
||||
"sv2","sv1"
|
||||
),
|
||||
"status" => (object) array(
|
||||
"current_state" => 1,
|
||||
"problem_has_been_acknowledged" => 1
|
||||
)
|
||||
),
|
||||
"hostb;service4" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service4",
|
||||
"group" => array(
|
||||
"sv2","sv1"
|
||||
),
|
||||
"status" => (object) array(
|
||||
"current_state" => 1,
|
||||
"problem_has_been_acknowledged" => 1
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Backend\Statusdat;
|
||||
/**
|
||||
*
|
||||
* Test class for Servicelistquery
|
||||
* Created Mon, 18 Feb 2013 14:33:21 +0000
|
||||
*
|
||||
**/
|
||||
class ServicelistqueryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for ServicelistQuery::Init()
|
||||
*
|
||||
**/
|
||||
public function testInit()
|
||||
{
|
||||
$this->markTestIncomplete('testInit is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Backend;
|
||||
/**
|
||||
*
|
||||
* Test class for Statusdat
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class StatusdatTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Statusdat::Init()
|
||||
*
|
||||
**/
|
||||
public function testInit()
|
||||
{
|
||||
$this->markTestIncomplete('testInit is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Statusdat::ListServices()
|
||||
*
|
||||
**/
|
||||
public function testListServices()
|
||||
{
|
||||
$this->markTestIncomplete('testListServices is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga;
|
||||
/**
|
||||
*
|
||||
* Test class for Backend
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class BackendTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Backend::GetInstance()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->markTestIncomplete('testGetInstance is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga;
|
||||
/**
|
||||
*
|
||||
* Test class for Benchmark
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class BenchmarkTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Benchmark::Measure()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testMeasure()
|
||||
{
|
||||
$this->markTestIncomplete('testMeasure is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Benchmark::Reset()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testReset()
|
||||
{
|
||||
$this->markTestIncomplete('testReset is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Benchmark::GetStartTime()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testGetStartTime()
|
||||
{
|
||||
$this->markTestIncomplete('testGetStartTime is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Benchmark::Dump()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testDump()
|
||||
{
|
||||
$this->markTestIncomplete('testDump is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Benchmark::RenderToText()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testRenderToText()
|
||||
{
|
||||
$this->markTestIncomplete('testRenderToText is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Benchmark::RenderToHtml()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testRenderToHtml()
|
||||
{
|
||||
$this->markTestIncomplete('testRenderToHtml is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga;
|
||||
/**
|
||||
*
|
||||
* Test class for Config
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Config::Get()
|
||||
*
|
||||
**/
|
||||
public function testGet()
|
||||
{
|
||||
$this->markTestIncomplete('testGet is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Config::__get()
|
||||
*
|
||||
**/
|
||||
public function test__get()
|
||||
{
|
||||
$this->markTestIncomplete('test__get is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Config::__set()
|
||||
*
|
||||
**/
|
||||
public function test__set()
|
||||
{
|
||||
$this->markTestIncomplete('test__set is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Config::Create()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testCreate()
|
||||
{
|
||||
$this->markTestIncomplete('testCreate is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga;
|
||||
/**
|
||||
*
|
||||
* Test class for Format
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class FormatTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Format::Bytes()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testBytes()
|
||||
{
|
||||
$this->markTestIncomplete('testBytes is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Ido;
|
||||
/**
|
||||
*
|
||||
* Test class for Db
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class DbTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Db::Module()
|
||||
*
|
||||
**/
|
||||
public function testModule()
|
||||
{
|
||||
$this->markTestIncomplete('testModule is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Db::GetDb()
|
||||
*
|
||||
**/
|
||||
public function testGetDb()
|
||||
{
|
||||
$this->markTestIncomplete('testGetDb is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Db::GetPrefix()
|
||||
*
|
||||
**/
|
||||
public function testGetPrefix()
|
||||
{
|
||||
$this->markTestIncomplete('testGetPrefix is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Comment as Comment;
|
||||
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
|
||||
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/IComment.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/Comment.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/CommandPipe.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/Acknowledgement.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/Exception/InvalidCommandException.php");
|
||||
|
||||
class AcknowledgementTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
|
||||
public function testAcknowledgeHostMessage()
|
||||
{
|
||||
$ack = new \Icinga\Protocol\Commandpipe\Acknowledgement(new Comment("author","commentdata"),false);
|
||||
$this->assertEquals("ACKNOWLEDGE_HOST_PROBLEM;%s;0;0;0;author;commentdata",$ack->getFormatString(CommandPipe::TYPE_HOST));
|
||||
|
||||
$ack->setExpireTime(1000);
|
||||
$this->assertEquals("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;%s;0;0;0;1000;author;commentdata",$ack->getFormatString(CommandPipe::TYPE_HOST));
|
||||
}
|
||||
|
||||
public function testAcknowledgeServiceMessage()
|
||||
{
|
||||
$ack = new \Icinga\Protocol\Commandpipe\Acknowledgement(new Comment("author","commentdata"),false);
|
||||
$this->assertEquals("ACKNOWLEDGE_SVC_PROBLEM;%s;%s;0;0;0;author;commentdata",$ack->getFormatString(CommandPipe::TYPE_SERVICE));
|
||||
|
||||
$ack->setExpireTime(1000);
|
||||
$this->assertEquals("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE;%s;%s;0;0;0;1000;author;commentdata",$ack->getFormatString(CommandPipe::TYPE_SERVICE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icinga\Protocol\Commandpipe\Exception\InvalidCommandException
|
||||
*/
|
||||
public function testInvalidServicegroupAcknowledgement()
|
||||
{
|
||||
$ack = new \Icinga\Protocol\Commandpipe\Acknowledgement(new Comment("author","commentdata"),false);
|
||||
$ack->getFormatString(CommandPipe::TYPE_SERVICEGROUP);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icinga\Protocol\Commandpipe\Exception\InvalidCommandException
|
||||
*/
|
||||
public function testInvalidHostgroupAcknowledgement()
|
||||
{
|
||||
$ack = new \Icinga\Protocol\Commandpipe\Acknowledgement(new Comment("author","commentdata"),false);
|
||||
$ack->getFormatString(CommandPipe::TYPE_HOSTGROUP);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,310 @@
|
|||
<?php
|
||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Comment as Comment;
|
||||
use Icinga\Protocol\Commandpipe\Acknowledgement as Acknowledgement;
|
||||
use Icinga\Protocol\Commandpipe\Downtime as Downtime;
|
||||
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
|
||||
use \Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
|
||||
|
||||
require_once("Zend/Config.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/IComment.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/Comment.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/CommandPipe.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/Acknowledgement.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/Downtime.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/PropertyModifier.php");
|
||||
require_once("../library/Icinga/Protocol/Commandpipe/Exception/InvalidCommandException.php");
|
||||
|
||||
if(!defined("EXTCMD_TEST_BIN"))
|
||||
define("EXTCMD_TEST_BIN", "./bin/extcmd_test");
|
||||
|
||||
class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function getPipeName()
|
||||
{
|
||||
return sys_get_temp_dir()."/icinga_test_pipe";
|
||||
}
|
||||
private function getTestPipe()
|
||||
{
|
||||
$tmpPipe = $this->getPipeName();
|
||||
$this->cleanup();
|
||||
touch($tmpPipe);
|
||||
|
||||
$cfg = new \Zend_Config(array(
|
||||
"path" => $tmpPipe,
|
||||
"name" => "test"
|
||||
));
|
||||
$comment = new Comment("Autor","Comment");
|
||||
$pipe = new Commandpipe($cfg);
|
||||
|
||||
return $pipe;
|
||||
}
|
||||
|
||||
private function cleanup() {
|
||||
if(file_exists($this->getPipeName()))
|
||||
unlink($this->getPipeName());
|
||||
}
|
||||
|
||||
private function assertCommandSucceeded($expectedString = false,$command = false) {
|
||||
$resultCode = null;
|
||||
$resultArr = array();
|
||||
$receivedCmd = exec(EXTCMD_TEST_BIN." ".escapeshellarg($command ? $command : file_get_contents($this->getPipeName())),$resultArr,$resultCode);
|
||||
$this->assertEquals(0,$resultCode,"Submit of external command returned error : ".$receivedCmd);
|
||||
if (!$expectedString)
|
||||
return;
|
||||
$this->assertEquals(
|
||||
$expectedString,
|
||||
$receivedCmd
|
||||
);
|
||||
}
|
||||
public function testAcknowledgeSingleHost()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$ack = new Acknowledgement(new Comment("I can","sends teh ack"));
|
||||
$pipe->acknowledge(array(
|
||||
(object) array(
|
||||
"host_name" => "hostA"
|
||||
)
|
||||
),$ack);
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack");
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testAcknowledgeMultipleObjects()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$ack = new Comment("I can","sends teh ack");
|
||||
$pipe->fopen_mode = "a";
|
||||
$pipe->acknowledge(array(
|
||||
(object) array(
|
||||
"host_name" => "hostA"
|
||||
),(object) array(
|
||||
"host_name" => "hostB"
|
||||
),(object) array(
|
||||
"host_name" => "hostC"
|
||||
),(object) array(
|
||||
"host_name" => "hostC",
|
||||
"service_description" => "svc"
|
||||
)
|
||||
),$ack);
|
||||
|
||||
$result = explode("\n",file_get_contents($this->getPipeName()));
|
||||
|
||||
$this->assertCount(5,$result);
|
||||
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack",$result[0]);
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostB;0;0;0;I can;sends teh ack",$result[1]);
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostC;0;0;0;I can;sends teh ack",$result[2]);
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_SVC_PROBLEM;hostC;svc;0;0;0;I can;sends teh ack",$result[3]);
|
||||
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testAddHostComment()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$pipe->addComment(array((object) array("host_name" => "hostA")),
|
||||
new Comment("Autor","Comment")
|
||||
);
|
||||
$this->assertCommandSucceeded("ADD_HOST_COMMENT;hostA;0;Autor;Comment");
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testRemoveAllHostComment()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$pipe->removeComment(array(
|
||||
(object) array(
|
||||
"host_name" => "test"
|
||||
)
|
||||
));
|
||||
$this->assertCommandSucceeded("DEL_ALL_HOST_COMMENTS;test");
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testRemoveSpecificComment()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$pipe->removeComment(array((object) array("comment_id"=>34,"host_name"=>"test")));
|
||||
$this->assertCommandSucceeded("DEL_HOST_COMMENT;34");
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testScheduleChecks()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$pipe->fopen_mode = "a"; // append so we have multiple results
|
||||
$t = time();
|
||||
// normal reschedule
|
||||
$pipe->scheduleCheck(array(
|
||||
(object) array("host_name"=>"test"),
|
||||
(object) array("host_name"=>"test","service_description"=>"svc1")
|
||||
),$t);
|
||||
// forced
|
||||
$pipe->scheduleForcedCheck(array(
|
||||
(object) array("host_name"=>"test"),
|
||||
(object) array("host_name"=>"test","service_description"=>"svc1")
|
||||
),$t);
|
||||
// forced, recursive
|
||||
$pipe->scheduleForcedCheck(array(
|
||||
(object) array("host_name"=>"test"),
|
||||
),$t,true);
|
||||
|
||||
$result = explode("\n",file_get_contents($this->getPipeName()));
|
||||
$this->assertCount(6,$result);
|
||||
|
||||
$this->assertCommandSucceeded("SCHEDULE_HOST_CHECK;test;".$t,$result[0]);
|
||||
$this->assertCommandSucceeded("SCHEDULE_SVC_CHECK;test;svc1;".$t,$result[1]);
|
||||
$this->assertCommandSucceeded("SCHEDULE_FORCED_HOST_CHECK;test;".$t,$result[2]);
|
||||
$this->assertCommandSucceeded("SCHEDULE_FORCED_SVC_CHECK;test;svc1;".$t,$result[3]);
|
||||
$this->assertCommandSucceeded("SCHEDULE_FORCED_HOST_SVC_CHECKS;test;".$t,$result[4]);
|
||||
|
||||
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testObjectStateModifications()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$pipe->fopen_mode = "a";
|
||||
$pipe->setMonitoringProperties(array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost"
|
||||
),
|
||||
(object) array(
|
||||
"host_name" => "host",
|
||||
"service_description" => "svc"
|
||||
)
|
||||
), new MONFLAG(array(
|
||||
MONFLAG::ACTIVE => MONFLAG::STATE_DISABLE,
|
||||
MONFLAG::PASSIVE => MONFLAG::STATE_ENABLE,
|
||||
MONFLAG::NOTIFICATIONS => MONFLAG::STATE_DISABLE,
|
||||
MONFLAG::EVENTHANDLER => MONFLAG::STATE_ENABLE,
|
||||
MONFLAG::FLAPPING => MONFLAG::STATE_DISABLE,
|
||||
MONFLAG::FRESHNESS => MONFLAG::STATE_ENABLE,
|
||||
))
|
||||
);
|
||||
|
||||
$result = explode("\n",file_get_contents($this->getPipeName()));
|
||||
array_pop($result); // remove empty last line
|
||||
$this->assertCount(12,$result);
|
||||
foreach ($result as $command) {
|
||||
$this->assertCommandSucceeded(false,$command);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testGlobalNotificationTrigger()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$pipe->enableGlobalNotifications();
|
||||
$this->assertCommandSucceeded("ENABLE_NOTIFICATIONS;");
|
||||
$pipe->disableGlobalNotifications();
|
||||
$this->assertCommandSucceeded("DISABLE_NOTIFICATIONS;");
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testScheduleDowntime()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$downtime = new Downtime(25,26,new Comment("me","test"));
|
||||
$pipe->scheduleDowntime(array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost"
|
||||
)
|
||||
),$downtime);
|
||||
$this->assertCommandSucceeded("SCHEDULE_HOST_DOWNTIME;Testhost;25;26;0;0;0;me;test");
|
||||
|
||||
$pipe->scheduleDowntime(array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost",
|
||||
"service_description" => "svc"
|
||||
)
|
||||
),$downtime);
|
||||
$this->assertCommandSucceeded("SCHEDULE_SVC_DOWNTIME;Testhost;svc;25;26;0;0;0;me;test");
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
public function testRemoveDowntime()
|
||||
{
|
||||
$pipe = $this->getTestPipe();
|
||||
try {
|
||||
$pipe->fopen_mode = "a";
|
||||
$pipe->removeDowntime(array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost"
|
||||
),
|
||||
(object) array(
|
||||
"host_name" => "host",
|
||||
"service_description" => "svc"
|
||||
),
|
||||
(object) array(
|
||||
"host_name" => "host",
|
||||
"service_description" => "svc",
|
||||
"downtime_id" => 123
|
||||
)
|
||||
));
|
||||
$result = explode("\n",file_get_contents($this->getPipeName()));
|
||||
array_pop($result); // remove empty last line
|
||||
$this->assertCount(3,$result);
|
||||
$this->assertCommandSucceeded("DEL_DOWNTIME_BY_HOST_NAME;Testhost",$result[0]);
|
||||
$this->assertCommandSucceeded("DEL_DOWNTIME_BY_HOST_NAME;host;svc",$result[1]);
|
||||
$this->assertCommandSucceeded("DEL_SVC_DOWNTIME;123",$result[2]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Ldap;
|
||||
/**
|
||||
*
|
||||
* Test class for Connection
|
||||
* Created Tue, 12 Mar 2013 17:08:12 +0000
|
||||
*
|
||||
**/
|
||||
class ConnectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Connection::GetDN()
|
||||
*
|
||||
**/
|
||||
public function testGetDN()
|
||||
{
|
||||
$this->markTestIncomplete('testGetDN is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Connection::Root()
|
||||
*
|
||||
**/
|
||||
public function testRoot()
|
||||
{
|
||||
$this->markTestIncomplete('testRoot is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Connection::Select()
|
||||
*
|
||||
**/
|
||||
public function testSelect()
|
||||
{
|
||||
$this->markTestIncomplete('testSelect is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Connection::FetchOne()
|
||||
*
|
||||
**/
|
||||
public function testFetchOne()
|
||||
{
|
||||
$this->markTestIncomplete('testFetchOne is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Connection::FetchRow()
|
||||
*
|
||||
**/
|
||||
public function testFetchRow()
|
||||
{
|
||||
$this->markTestIncomplete('testFetchRow is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Connection::FetchAll()
|
||||
*
|
||||
**/
|
||||
public function testFetchAll()
|
||||
{
|
||||
$this->markTestIncomplete('testFetchAll is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Ldap;
|
||||
/**
|
||||
*
|
||||
* Test class for Ldaputils
|
||||
* Created Tue, 12 Mar 2013 17:08:12 +0000
|
||||
*
|
||||
**/
|
||||
class LdaputilsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for LdapUtils::ExplodeDN()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testExplodeDN()
|
||||
{
|
||||
$this->markTestIncomplete('testExplodeDN is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for LdapUtils::ImplodeDN()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testImplodeDN()
|
||||
{
|
||||
$this->markTestIncomplete('testImplodeDN is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for LdapUtils::QuoteForDN()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testQuoteForDN()
|
||||
{
|
||||
$this->markTestIncomplete('testQuoteForDN is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for LdapUtils::QuoteForSearch()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testQuoteForSearch()
|
||||
{
|
||||
$this->markTestIncomplete('testQuoteForSearch is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Ldap;
|
||||
/**
|
||||
*
|
||||
* Test class for Node
|
||||
* Created Tue, 12 Mar 2013 17:08:12 +0000
|
||||
*
|
||||
**/
|
||||
class NodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Node::GetRDN()
|
||||
*
|
||||
**/
|
||||
public function testGetRDN()
|
||||
{
|
||||
$this->markTestIncomplete('testGetRDN is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Node::GetDN()
|
||||
*
|
||||
**/
|
||||
public function testGetDN()
|
||||
{
|
||||
$this->markTestIncomplete('testGetDN is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Node::__get()
|
||||
*
|
||||
**/
|
||||
public function test__get()
|
||||
{
|
||||
$this->markTestIncomplete('test__get is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Node::CreateWithRDN()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testCreateWithRDN()
|
||||
{
|
||||
$this->markTestIncomplete('testCreateWithRDN is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
namespace Tests\Icinga\Protocol\Ldap;
|
||||
require_once '../library/Icinga/Protocol/Ldap/Query.php';
|
||||
require_once '../library/Icinga/Protocol/Ldap/Connection.php';
|
||||
require_once '../library/Icinga/Protocol/Ldap/LdapUtils.php';
|
||||
/**
|
||||
*
|
||||
* Test class for Query
|
||||
* Created Wed, 13 Mar 2013 12:57:11 +0000
|
||||
*
|
||||
**/
|
||||
class QueryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private function emptySelect()
|
||||
{
|
||||
$connection = new \Icinga\Protocol\Ldap\Connection((object) array(
|
||||
'hostname' => 'localhost',
|
||||
'root_dn' => 'dc=example,dc=com',
|
||||
'bind_dn' => 'cn=user,ou=users,dc=example,dc=com',
|
||||
'bind_pw' => '***'
|
||||
));
|
||||
return $connection->select();
|
||||
}
|
||||
|
||||
private function prepareSelect()
|
||||
{
|
||||
$select = $this->emptySelect();
|
||||
$select->from('dummyClass', array('testIntColumn', 'testStringColumn'))
|
||||
->where('testIntColumn', 1)
|
||||
->where('testStringColumn', 'test')
|
||||
->where('testWildcard', 'abc*')
|
||||
->order('testIntColumn')
|
||||
->limit(10, 4);
|
||||
return $select;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Count() - shall be tested with connection
|
||||
*
|
||||
**/
|
||||
public function testCount()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Limit()
|
||||
*
|
||||
**/
|
||||
public function testLimit()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
$this->assertEquals(10, $select->getLimit());
|
||||
$this->assertEquals(4, $select->getOffset());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::HasLimit()
|
||||
*
|
||||
**/
|
||||
public function testHasLimit()
|
||||
{
|
||||
$select = $this->emptySelect();
|
||||
$this->assertFalse($select->hasLimit());
|
||||
$select = $this->prepareSelect();
|
||||
$this->assertTrue($select->hasLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::HasOffset()
|
||||
*
|
||||
**/
|
||||
public function testHasOffset()
|
||||
{
|
||||
$select = $this->emptySelect();
|
||||
$this->assertFalse($select->hasOffset());
|
||||
$select = $this->prepareSelect();
|
||||
$this->assertTrue($select->hasOffset());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::GetLimit()
|
||||
*
|
||||
**/
|
||||
public function testGetLimit()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
$this->assertEquals(10, $select->getLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::GetOffset()
|
||||
*
|
||||
**/
|
||||
public function testGetOffset()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
$this->assertEquals(10, $select->getLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchTree()
|
||||
*
|
||||
**/
|
||||
public function testFetchTree()
|
||||
{
|
||||
$this->markTestIncomplete('testFetchTree is not implemented yet - requires real LDAP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchAll() - shall be tested with connection
|
||||
*
|
||||
**/
|
||||
public function testFetchAll()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchRow() - shall be tested with connection
|
||||
*
|
||||
**/
|
||||
public function testFetchRow()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchOne()
|
||||
*
|
||||
**/
|
||||
public function testFetchOne()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchPairs()
|
||||
*
|
||||
**/
|
||||
public function testFetchPairs()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::From()
|
||||
*
|
||||
**/
|
||||
public function testFrom()
|
||||
{
|
||||
return $this->testListFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Where()
|
||||
*
|
||||
**/
|
||||
public function testWhere()
|
||||
{
|
||||
$this->markTestIncomplete('testWhere is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Order()
|
||||
*
|
||||
**/
|
||||
public function testOrder()
|
||||
{
|
||||
$select = $this->emptySelect()->order('bla');
|
||||
// tested by testGetSortColumns
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::ListFields()
|
||||
*
|
||||
**/
|
||||
public function testListFields()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
$this->assertEquals(
|
||||
array('testIntColumn', 'testStringColumn'),
|
||||
$select->listFields()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::GetSortColumns()
|
||||
*
|
||||
**/
|
||||
public function testGetSortColumns()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
$cols = $select->getSortColumns();
|
||||
$this->assertEquals('testIntColumn', $cols[0][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Paginate() - requires real result
|
||||
*
|
||||
**/
|
||||
public function testPaginate()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::__toString()
|
||||
*
|
||||
**/
|
||||
public function test__toString()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
$res = '(&(objectClass=dummyClass)(testIntColumn=1)(testStringColumn=test)(testWildcard=abc*))';
|
||||
$this->assertEquals($res, (string) $select);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::__destruct()
|
||||
*
|
||||
**/
|
||||
public function test__destruct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Ldap;
|
||||
/**
|
||||
*
|
||||
* Test class for Root
|
||||
* Created Tue, 12 Mar 2013 17:08:12 +0000
|
||||
*
|
||||
**/
|
||||
class RootTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Root::HasParent()
|
||||
*
|
||||
**/
|
||||
public function testHasParent()
|
||||
{
|
||||
$this->markTestIncomplete('testHasParent is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Root::GetConnection()
|
||||
*
|
||||
**/
|
||||
public function testGetConnection()
|
||||
{
|
||||
$this->markTestIncomplete('testGetConnection is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Root::HasBeenChanged()
|
||||
*
|
||||
**/
|
||||
public function testHasBeenChanged()
|
||||
{
|
||||
$this->markTestIncomplete('testHasBeenChanged is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Root::GetRDN()
|
||||
*
|
||||
**/
|
||||
public function testGetRDN()
|
||||
{
|
||||
$this->markTestIncomplete('testGetRDN is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Root::GetDN()
|
||||
*
|
||||
**/
|
||||
public function testGetDN()
|
||||
{
|
||||
$this->markTestIncomplete('testGetDN is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Root::__get()
|
||||
*
|
||||
**/
|
||||
public function test__get()
|
||||
{
|
||||
$this->markTestIncomplete('test__get is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Root::ForConnection()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testForConnection()
|
||||
{
|
||||
$this->markTestIncomplete('testForConnection is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Livestatus;
|
||||
/**
|
||||
*
|
||||
* Test class for Connection
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class ConnectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Connection::HasTable()
|
||||
*
|
||||
**/
|
||||
public function testHasTable()
|
||||
{
|
||||
$this->markTestIncomplete('testHasTable is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Connection::Select()
|
||||
*
|
||||
**/
|
||||
public function testSelect()
|
||||
{
|
||||
$this->markTestIncomplete('testSelect is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Connection::FetchAll()
|
||||
*
|
||||
**/
|
||||
public function testFetchAll()
|
||||
{
|
||||
$this->markTestIncomplete('testFetchAll is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Connection::Disconnect()
|
||||
*
|
||||
**/
|
||||
public function testDisconnect()
|
||||
{
|
||||
$this->markTestIncomplete('testDisconnect is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Connection::__destruct()
|
||||
*
|
||||
**/
|
||||
public function test__destruct()
|
||||
{
|
||||
$this->markTestIncomplete('test__destruct is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Livestatus;
|
||||
/**
|
||||
*
|
||||
* Test class for Query
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class QueryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Query::Compare()
|
||||
*
|
||||
**/
|
||||
public function testCompare()
|
||||
{
|
||||
$this->markTestIncomplete('testCompare is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::HasOrder()
|
||||
*
|
||||
**/
|
||||
public function testHasOrder()
|
||||
{
|
||||
$this->markTestIncomplete('testHasOrder is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Where()
|
||||
*
|
||||
**/
|
||||
public function testWhere()
|
||||
{
|
||||
$this->markTestIncomplete('testWhere is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Order()
|
||||
*
|
||||
**/
|
||||
public function testOrder()
|
||||
{
|
||||
$this->markTestIncomplete('testOrder is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Limit()
|
||||
*
|
||||
**/
|
||||
public function testLimit()
|
||||
{
|
||||
$this->markTestIncomplete('testLimit is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::HasLimit()
|
||||
*
|
||||
**/
|
||||
public function testHasLimit()
|
||||
{
|
||||
$this->markTestIncomplete('testHasLimit is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::HasOffset()
|
||||
*
|
||||
**/
|
||||
public function testHasOffset()
|
||||
{
|
||||
$this->markTestIncomplete('testHasOffset is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::GetLimit()
|
||||
*
|
||||
**/
|
||||
public function testGetLimit()
|
||||
{
|
||||
$this->markTestIncomplete('testGetLimit is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::GetOffset()
|
||||
*
|
||||
**/
|
||||
public function testGetOffset()
|
||||
{
|
||||
$this->markTestIncomplete('testGetOffset is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::From()
|
||||
*
|
||||
**/
|
||||
public function testFrom()
|
||||
{
|
||||
$this->markTestIncomplete('testFrom is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::HasColumns()
|
||||
*
|
||||
**/
|
||||
public function testHasColumns()
|
||||
{
|
||||
$this->markTestIncomplete('testHasColumns is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::GetColumns()
|
||||
*
|
||||
**/
|
||||
public function testGetColumns()
|
||||
{
|
||||
$this->markTestIncomplete('testGetColumns is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::__toString()
|
||||
*
|
||||
**/
|
||||
public function test__toString()
|
||||
{
|
||||
$this->markTestIncomplete('test__toString is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::__destruct()
|
||||
*
|
||||
**/
|
||||
public function test__destruct()
|
||||
{
|
||||
$this->markTestIncomplete('test__destruct is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
|
||||
require_once("../library/Icinga/Protocol/Statusdat/IReader.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Reader.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Exception/ParsingException.php");
|
||||
require_once("../library/Icinga/Exception/ProgrammingError.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Parser.php");
|
||||
require_once("../library/Icinga/Protocol/AbstractQuery.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Query.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Query/IQueryPart.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Query/Group.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Query/Expression.php");
|
||||
require_once("../library/Icinga/Exception/ConfigurationError.php");
|
||||
require_once("Zend/Config.php");
|
||||
use \Icinga\Protocol\Statusdat as SD;
|
||||
|
||||
/**
|
||||
* This is a high level test for the whole statusdat component, i.e. all parts put together
|
||||
* and called like they would be in a real situation. This should work when all isolated tests have passed.
|
||||
*/
|
||||
class StatusdatComponentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function getReader() {
|
||||
$reader = new SD\Reader(new \Zend_Config(array(
|
||||
"status_file" => dirname(__FILE__)."/status.dat",
|
||||
"objects_file" => dirname(__FILE__)."/objects.cache"
|
||||
)),null,true);
|
||||
return $reader;
|
||||
}
|
||||
|
||||
public function testServicegroupFilterFromService() {
|
||||
$r = $this->getReader();
|
||||
$group = array(array('a1','b2'));
|
||||
$result = $r->select()->from("services")->where("group IN ?",$group)->getResult();
|
||||
$this->assertCount(2,$result);
|
||||
foreach($result as $obj) {
|
||||
$this->assertTrue(is_object($obj));
|
||||
}
|
||||
}
|
||||
|
||||
public function testServicegroupFilterFromHost() {
|
||||
$r = $this->getReader();
|
||||
$group = array(array('a1','b2'));
|
||||
$result = $r->select()->from("hosts")->where("services.group IN ?",$group)->getResult();
|
||||
$this->assertCount(2,$result);
|
||||
foreach($result as $obj) {
|
||||
$this->assertTrue(is_object($obj));
|
||||
}
|
||||
}
|
||||
|
||||
public function testHostgroupFilterFromHost() {
|
||||
$r = $this->getReader();
|
||||
$group = array(array('exc-hostb'));
|
||||
$result = $r->select()->from("hosts")->where("group IN ?",$group)->getResult();
|
||||
$this->assertCount(2,$result);
|
||||
foreach($result as $obj) {
|
||||
$this->assertTrue(is_object($obj));
|
||||
}
|
||||
}
|
||||
|
||||
public function testHostgroupFilterFromService() {
|
||||
$r = $this->getReader();
|
||||
$group = array(array('exc-hostb'));
|
||||
$result = $r->select()->from("services")->where("host.group IN ?",$group)->getResult();
|
||||
|
||||
$this->assertCount(6,$result);
|
||||
foreach($result as $obj) {
|
||||
$this->assertTrue(is_object($obj));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
define servicegroup {
|
||||
servicegroup_name sv1
|
||||
alias testsv1
|
||||
members hosta,servicea1,hostb,serviceb1,hostc,servicec1
|
||||
}
|
||||
|
||||
define servicegroup {
|
||||
servicegroup_name a1
|
||||
alias testsa1
|
||||
members hosta,servicea1
|
||||
}
|
||||
|
||||
define servicegroup {
|
||||
servicegroup_name b2
|
||||
alias testsb2
|
||||
members hostb,serviceb2
|
||||
}
|
||||
|
||||
define servicegroup {
|
||||
servicegroup_name sv2
|
||||
alias testsv2
|
||||
members hosta,servicea2,hostb,serviceb2,hostc,servicec2
|
||||
}
|
||||
|
||||
define hostgroup {
|
||||
hostgroup_name all-hosts
|
||||
alias All hosts
|
||||
members hosta,hostb,hostc
|
||||
}
|
||||
|
||||
define hostgroup {
|
||||
hostgroup_name exc-hostb
|
||||
alias Excluded host b
|
||||
members hosta,hostc
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name hosta
|
||||
alias hosta
|
||||
address 127.0.0.5
|
||||
parents hosta
|
||||
check_period 24x7
|
||||
check_command check-host-alive
|
||||
contact_groups admins
|
||||
notification_period workhours
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name hostb
|
||||
alias hostb
|
||||
address 127.0.0.5
|
||||
parents hostb
|
||||
check_period 24x7
|
||||
check_command check-host-alive
|
||||
contact_groups admins
|
||||
notification_period workhours
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name hostc
|
||||
alias hostc
|
||||
address 127.0.0.5
|
||||
parents hostc
|
||||
check_period 24x7
|
||||
check_command check-host-alive
|
||||
contact_groups admins
|
||||
notification_period workhours
|
||||
}
|
||||
|
||||
define service {
|
||||
host_name hosta
|
||||
service_description servicea1
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
|
||||
define service {
|
||||
host_name hosta
|
||||
service_description servicea2
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hosta
|
||||
service_description servicea3
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostb
|
||||
service_description serviceb1
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostb
|
||||
service_description serviceb2
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostb
|
||||
service_description serviceb3
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostc
|
||||
service_description servicec1
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostc
|
||||
service_description servicec2
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostc
|
||||
service_description servicec3
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace Icinga\Protocol\Statusdat\Exceptions;
|
||||
|
||||
class ParsingException extends RuntimeException
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Exception/ParsingException.php");
|
||||
require_once("../library/Icinga/Exception/ProgrammingError.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Parser.php");
|
||||
use Icinga\Protocol\Statusdat\Parser;
|
||||
/**
|
||||
*
|
||||
* Test class for Parser
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class ParserTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
private function getStringAsFileHandle($string)
|
||||
{
|
||||
$maxsize = strlen($string)*2;
|
||||
$fhandle = fopen("php://memory", 'r+');
|
||||
fputs($fhandle,$string);
|
||||
rewind($fhandle);
|
||||
return $fhandle;
|
||||
}
|
||||
|
||||
public function testSimpleObjectCacheParsing()
|
||||
{
|
||||
$fd = $this->getStringAsFileHandle("
|
||||
define hostescalation {
|
||||
host_name\ttest
|
||||
key\tvalue
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name\ttest
|
||||
alias\ttest123
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name\ttest2
|
||||
alias\ttest123
|
||||
}
|
||||
|
||||
define service {
|
||||
host_name\ttest
|
||||
service_description\tCurrent Users
|
||||
}
|
||||
|
||||
|
||||
define servicegroup {
|
||||
servicegroup_name\tgroup
|
||||
members\ttest,Current Users
|
||||
}
|
||||
");
|
||||
$testParser = new Parser($fd);
|
||||
$testParser->parseObjectsFile();
|
||||
$state = $testParser->getRuntimeState();
|
||||
$this->assertTrue(is_array($state));
|
||||
$this->assertTrue(isset($state["host"]));
|
||||
$this->assertTrue(isset($state["service"]));
|
||||
$this->assertEquals("test",$state["host"]["test"]->host_name);
|
||||
$this->assertTrue(is_array($state["host"]["test"]->escalation));
|
||||
$this->assertTrue(isset($state["service"]["test;Current Users"]->group));
|
||||
$this->assertTrue(is_array($state["service"]["test;Current Users"]->group));
|
||||
$this->assertCount(1,$state["service"]["test;Current Users"]->group);
|
||||
$this->assertEquals("group",$state["service"]["test;Current Users"]->group[0]);
|
||||
$this->assertEquals("value",$state["host"]["test"]->escalation[0]->key);
|
||||
$this->assertEquals("test2",$state["host"]["test2"]->host_name);
|
||||
}
|
||||
|
||||
public function testRuntimeParsing()
|
||||
{
|
||||
$baseState = array(
|
||||
"host" => array(
|
||||
"test" => (object) array(
|
||||
"host_name" => "test"
|
||||
),
|
||||
"test2" => (object) array(
|
||||
"host_name" => "test2"
|
||||
)
|
||||
),
|
||||
"service" => array(
|
||||
"test;Current Users" => (object) array(
|
||||
"host_name" => "test",
|
||||
"service_description" => "Current Users"
|
||||
)
|
||||
)
|
||||
);
|
||||
$fd = $this->getStringAsFileHandle(self::RUNTIME_STATE1);
|
||||
|
||||
$testParser = new Parser($fd, $baseState);
|
||||
$testParser->parseRuntimeState();
|
||||
$state = $testParser->getRuntimeState();
|
||||
|
||||
$this->assertTrue(isset($state["host"]["test"]->status));
|
||||
$this->assertEquals(3,$state["host"]["test"]->status->current_state);
|
||||
|
||||
$this->assertTrue(is_array($state["host"]["test"]->comment));
|
||||
$this->assertEquals(2,count($state["host"]["test"]->comment));
|
||||
}
|
||||
|
||||
public function testOverwriteRuntime()
|
||||
{
|
||||
$baseState = array(
|
||||
"host" => array(
|
||||
"test" => (object) array(
|
||||
"host_name" => "test"
|
||||
),
|
||||
"test2" => (object) array(
|
||||
"host_name" => "test2"
|
||||
)
|
||||
),
|
||||
"service" => array(
|
||||
"test;Current Users" => (object) array(
|
||||
"host_name" => "test",
|
||||
"service_description" => "Current Users"
|
||||
)
|
||||
)
|
||||
);
|
||||
$fd = $this->getStringAsFileHandle(self::RUNTIME_STATE1);
|
||||
|
||||
|
||||
$testParser = new Parser($fd, $baseState);
|
||||
$testParser->parseRuntimeState();
|
||||
$state = $testParser->getRuntimeState();
|
||||
|
||||
$this->assertTrue(isset($state["host"]["test"]->status));
|
||||
$this->assertEquals(3,$state["host"]["test"]->status->current_state);
|
||||
|
||||
$this->assertTrue(is_array($state["host"]["test"]->comment));
|
||||
$this->assertEquals(2,count($state["host"]["test"]->comment));
|
||||
|
||||
$fd = $this->getStringAsFileHandle(self::RUNTIME_STATE2);
|
||||
$testParser->parseRuntimeState($fd);
|
||||
$state = $testParser->getRuntimeState();
|
||||
|
||||
$this->assertTrue(isset($state["host"]["test"]->status));
|
||||
$this->assertEquals(2,$state["host"]["test"]->status->current_state);
|
||||
$this->assertTrue(is_array($state["host"]["test"]->comment));
|
||||
$this->assertEquals(3,count($state["host"]["test"]->comment));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert no errors occuring
|
||||
*/
|
||||
public function testRuntimeParsingForBigFile()
|
||||
{
|
||||
$this->markTestSkipped('Skipped slow tests');
|
||||
$objects = fopen("res/status/objects.cache","r");
|
||||
$status = fopen("res/status/status.big.dat","r");
|
||||
$testParser = new Parser($objects);
|
||||
$testParser->parseObjectsFile();
|
||||
$testParser->parseRuntimeState($status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert no errors occuring
|
||||
*/
|
||||
public function testRuntimeParsingForIcinga2()
|
||||
{
|
||||
$this->markTestSkipped('Skipped slow tests');
|
||||
$objects = fopen("res/status/objects.icinga2.cache","r");
|
||||
$status = fopen("res/status/status.icinga2.dat","r");
|
||||
$testParser = new Parser($objects);
|
||||
$testParser->parseObjectsFile();
|
||||
$testParser->parseRuntimeState($status);
|
||||
}
|
||||
|
||||
const RUNTIME_STATE1 = "
|
||||
|
||||
hoststatus {
|
||||
host_name=test
|
||||
current_state=3
|
||||
test=test123
|
||||
}
|
||||
|
||||
hoststatus {
|
||||
host_name=test2
|
||||
current_state=3
|
||||
test=test123
|
||||
}
|
||||
|
||||
servicestatus {
|
||||
host_name=test
|
||||
service_description=Current Users
|
||||
current_state=3
|
||||
}
|
||||
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value1
|
||||
}
|
||||
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value2
|
||||
}";
|
||||
const RUNTIME_STATE2 = "
|
||||
|
||||
hoststatus {
|
||||
host_name=test
|
||||
current_state=2
|
||||
test=test123
|
||||
}
|
||||
|
||||
hoststatus {
|
||||
host_name=test2
|
||||
current_state=2
|
||||
test=test123
|
||||
}
|
||||
|
||||
servicestatus {
|
||||
host_name=test
|
||||
service_description=Current Users
|
||||
current_state=2
|
||||
}
|
||||
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value14
|
||||
}
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value15
|
||||
}
|
||||
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value24
|
||||
}";
|
||||
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat\Query;
|
||||
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Query/IQueryPart.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Query/Expression.php");
|
||||
|
||||
use Icinga\Protocol\Statusdat\Query\Expression;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Expression
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class ExpressionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Expression::FromString()
|
||||
*
|
||||
**/
|
||||
public function testFromStringParsing()
|
||||
{
|
||||
$assertions = array(
|
||||
"expression > ?" => "IS_GREATER",
|
||||
"expression >= ?" => "IS_GREATER_EQ",
|
||||
"expression <= ?" => "IS_LESS_EQ",
|
||||
"expression < ?" => "IS_LESS",
|
||||
"expression = ?" => "IS_EQUAL",
|
||||
"expression != ?" => "IS_NOT_EQUAL",
|
||||
"expression like ?" => "IS_LIKE",
|
||||
"expression IN ? " => "IS_IN"
|
||||
);
|
||||
|
||||
foreach ($assertions as $query => $callback) {
|
||||
$expression = new Expression();
|
||||
$value = array(10);
|
||||
$expression->fromString($query, $value);
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("expression", $expression->getField());
|
||||
$this->assertEquals($callback, $expression->CB);
|
||||
}
|
||||
}
|
||||
|
||||
public function testNumericComparisons()
|
||||
{
|
||||
$assertions = array( // subarrays are (TEST,MATCHES)
|
||||
"expression < ?" => array(5, array(1, 2, 3, 4)),
|
||||
"expression <= ?" => array(5, array(1, 2, 3, 4, 5)),
|
||||
"expression >= ?" => array(5, array(5, 6, 7)),
|
||||
"expression > ?" => array(5, array(6, 7)),
|
||||
"expression = ?" => array(5, array(5)),
|
||||
"expression != ?" => array(5, array(1, 2, 3, 4, 6, 7)),
|
||||
"expression IN ?" => array(array(1, 5, 7), array(1, 5, 7))
|
||||
);
|
||||
|
||||
foreach ($assertions as $query => $test) {
|
||||
$expression = new Expression();
|
||||
|
||||
$value = array($test[0]);
|
||||
$testArray = array(
|
||||
(object)array("expression" => 1),
|
||||
(object)array("expression" => 2),
|
||||
(object)array("expression" => 3),
|
||||
(object)array("expression" => 4),
|
||||
(object)array("expression" => 5),
|
||||
(object)array("expression" => 6),
|
||||
(object)array("expression" => 7)
|
||||
);
|
||||
$expression->fromString($query, $value);
|
||||
$this->assertCount(0, $value);
|
||||
$result = $expression->filter($testArray);
|
||||
foreach ($result as $index) {
|
||||
$this->assertContains($index + 1, $test[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testNestedComparison()
|
||||
{
|
||||
|
||||
|
||||
$testArray = array(
|
||||
(object)array(
|
||||
"expression" => "atest",
|
||||
"state" => (object)array("value" => 1)
|
||||
),
|
||||
(object)array(
|
||||
"expression" => "testa",
|
||||
"state" => (object)array("value" => 2)
|
||||
)
|
||||
|
||||
);
|
||||
$expression = new Expression();
|
||||
$value = array(1);
|
||||
$expression->fromString("state.value > ?", $value);
|
||||
$this->assertCount(0, $value);
|
||||
|
||||
$result = $expression->filter($testArray);
|
||||
$this->assertEquals(1, count($result));
|
||||
$this->assertEquals(2, $testArray[$result[1]]->state->value);
|
||||
}
|
||||
|
||||
public function testNestedComparisonInArray()
|
||||
{
|
||||
$testArray = array(
|
||||
(object)array(
|
||||
"expression" => "atest",
|
||||
"state" => array((object) array("test"=>"1","test2"=>1))
|
||||
),
|
||||
(object)array(
|
||||
"expression" => "testa",
|
||||
"state" => array((object) array("test"=>"2","test2"=>2))
|
||||
)
|
||||
|
||||
);
|
||||
$expression = new Expression();
|
||||
$value = array(1);
|
||||
$expression->fromString("state.test > ?", $value);
|
||||
$this->assertCount(0, $value);
|
||||
|
||||
$result = $expression->filter($testArray);
|
||||
$this->assertEquals(1, count($result));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testCountQuery() {
|
||||
$testArray = array(
|
||||
(object)array(
|
||||
"expression" => "atest",
|
||||
"multiple" => array("test"=>"1","test2"=>1)
|
||||
),
|
||||
(object)array(
|
||||
"expression" => "testa",
|
||||
"multiple" => array("test"=>"2","test2"=>2,"test5"=>2,"test1"=>2,"test3"=>2,"test4"=>2)
|
||||
)
|
||||
);
|
||||
$expression = new Expression();
|
||||
$value = array(2);
|
||||
$expression->fromString("COUNT{multiple} > ?", $value);
|
||||
$this->assertCount(0, $value);
|
||||
|
||||
$result = $expression->filter($testArray);
|
||||
$this->assertEquals(1, count($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Expression::Filter()
|
||||
*
|
||||
**/
|
||||
public function testFilter()
|
||||
{
|
||||
$this->markTestIncomplete('testFilter is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat\Query;
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Query/IQueryPart.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Query/Group.php");
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Group
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
use Icinga\Protocol\Statusdat as Statusdat;
|
||||
|
||||
class QueryExpressionMock implements Statusdat\Query\IQueryPart
|
||||
{
|
||||
public $rawExpression;
|
||||
public $value;
|
||||
public $filter = array();
|
||||
|
||||
public function __construct($expression = null, &$value = array())
|
||||
{
|
||||
$this->value = array_shift($value);
|
||||
$this->rawExpression = $expression;
|
||||
|
||||
}
|
||||
|
||||
public function filter(array &$base, &$idx = null)
|
||||
{
|
||||
return array_intersect(array_values($idx), array_values($this->filter));
|
||||
}
|
||||
}
|
||||
|
||||
class GroupTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testParsingSingleCondition()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4);
|
||||
$testQuery->fromString("numeric_val >= ?", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(1, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
|
||||
$expression = $testQuery->getItems();
|
||||
$expression = $expression[0];
|
||||
|
||||
$this->assertEquals("numeric_val >= ?", $expression->rawExpression);
|
||||
$this->assertEquals(4, $expression->value);
|
||||
|
||||
}
|
||||
|
||||
public function testParsingSimpleAndCondition()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4, 'hosta');
|
||||
$testQuery->fromString("numeric_val >= ? AND host_name = ?", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(2, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("AND", $testQuery->getType());
|
||||
$items = $testQuery->getItems();
|
||||
|
||||
$expression0 = $items[0];
|
||||
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
|
||||
$this->assertEquals(4, $expression0->value);
|
||||
|
||||
$expression1 = $items[1];
|
||||
$this->assertEquals("host_name = ?", $expression1->rawExpression);
|
||||
$this->assertEquals("hosta", $expression1->value);
|
||||
}
|
||||
|
||||
public function testParsingSimpleORCondition()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4, 'hosta');
|
||||
$testQuery->fromString("numeric_val >= ? OR host_name = ?", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(2, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("OR", $testQuery->getType());
|
||||
$items = $testQuery->getItems();
|
||||
|
||||
$expression0 = $items[0];
|
||||
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
|
||||
$this->assertEquals(4, $expression0->value);
|
||||
|
||||
$expression1 = $items[1];
|
||||
$this->assertEquals("host_name = ?", $expression1->rawExpression);
|
||||
$this->assertEquals("hosta", $expression1->value);
|
||||
}
|
||||
|
||||
public function testParsingExplicitSubgroup()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4, 'service1', 'hosta');
|
||||
$testQuery->fromString("numeric_val >= ? AND (service_description = ? OR host_name = ?)", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(2, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("AND", $testQuery->getType());
|
||||
$items = $testQuery->getItems();
|
||||
|
||||
$expression0 = $items[0];
|
||||
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
|
||||
$this->assertEquals(4, $expression0->value);
|
||||
|
||||
$subgroup = $items[1];
|
||||
$this->assertInstanceOf("Icinga\Protocol\Statusdat\Query\Group", $subgroup);
|
||||
$this->assertEquals("OR", $subgroup->getType());
|
||||
$orItems = $subgroup->getItems();
|
||||
|
||||
$expression1 = $orItems[0];
|
||||
$this->assertEquals("service_description = ?", $expression1->rawExpression);
|
||||
$this->assertEquals("service1", $expression1->value);
|
||||
|
||||
$expression2 = $orItems[1];
|
||||
$this->assertEquals("host_name = ?", $expression2->rawExpression);
|
||||
$this->assertEquals("hosta", $expression2->value);
|
||||
}
|
||||
|
||||
public function testParsingImplicitSubgroup()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4, 'service1', 'hosta');
|
||||
$testQuery->fromString("numeric_val >= ? AND service_description = ? OR host_name = ?", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(2, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("AND", $testQuery->getType());
|
||||
$items = $testQuery->getItems();
|
||||
|
||||
$expression0 = $items[0];
|
||||
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
|
||||
$this->assertEquals(4, $expression0->value);
|
||||
|
||||
$subgroup = $items[1];
|
||||
$this->assertInstanceOf("Icinga\Protocol\Statusdat\Query\Group", $subgroup);
|
||||
$this->assertEquals("OR", $subgroup->getType());
|
||||
$orItems = $subgroup->getItems();
|
||||
|
||||
$expression1 = $orItems[0];
|
||||
$this->assertEquals("service_description = ?", $expression1->rawExpression);
|
||||
$this->assertEquals("service1", $expression1->value);
|
||||
|
||||
$expression2 = $orItems[1];
|
||||
$this->assertEquals("host_name = ?", $expression2->rawExpression);
|
||||
$this->assertEquals("hosta", $expression2->value);
|
||||
}
|
||||
|
||||
public function testAndFilter()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$testQuery->setType(Statusdat\Query\Group::TYPE_AND);
|
||||
$exp1 = new QueryExpressionMock();
|
||||
$exp1->filter = array(1, 2, 3, 4, 5, 6, 8);
|
||||
$exp2 = new QueryExpressionMock();
|
||||
$exp2->filter = array(3, 4, 8);
|
||||
$base = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
$this->assertEquals(array(3, 4, 8), array_values($testQuery->addItem($exp1)->addItem($exp2)->filter($base)));
|
||||
|
||||
}
|
||||
|
||||
public function testOrFilter()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$testQuery->setType(Statusdat\Query\Group::TYPE_OR);
|
||||
$exp1 = new QueryExpressionMock();
|
||||
$exp1->filter = array(1, 2, 3);
|
||||
$exp2 = new QueryExpressionMock();
|
||||
$exp2->filter = array(3, 4, 6, 8);
|
||||
$base = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
$this->assertEquals(array(1, 2, 3, 4, 6, 8), array_values($testQuery->addItem($exp1)->addItem($exp2)->filter($base)));
|
||||
}
|
||||
|
||||
public function testCombinedFilter()
|
||||
{
|
||||
$testQuery_and = new Statusdat\Query\Group();
|
||||
$testQuery_and->setType(Statusdat\Query\Group::TYPE_AND);
|
||||
$testQuery_or = new Statusdat\Query\Group();
|
||||
$testQuery_or->setType(Statusdat\Query\Group::TYPE_OR);
|
||||
$base = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
$and_exp1 = new QueryExpressionMock();
|
||||
$and_exp1->filter = array(1, 2, 3, 4, 5, 6, 8);
|
||||
$and_exp2 = new QueryExpressionMock();
|
||||
$and_exp2->filter = array(3, 4, 8);
|
||||
|
||||
$or_exp1 = new QueryExpressionMock();
|
||||
$or_exp1->filter = array(1, 2, 3);
|
||||
$or_exp2 = new QueryExpressionMock();
|
||||
$or_exp2->filter = array(3, 4, 6, 8);
|
||||
$this->assertEquals(array(3, 4, 8), array_values(
|
||||
$testQuery_and
|
||||
->addItem($and_exp1)
|
||||
->addItem($and_exp2)
|
||||
->addItem($testQuery_or->addItem($or_exp1)->addItem($or_exp2))
|
||||
->filter($base))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
require_once("../library/Icinga/Protocol/AbstractQuery.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Query.php");
|
||||
require_once(dirname(__FILE__)."/ReaderMock.php");
|
||||
|
||||
|
||||
use Icinga\Protocol\Statusdat as Statusdat;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Query
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class QueryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testSimpleServiceSelect()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
|
||||
$result = & $query->from("services")->getResult();
|
||||
$objects = $readerMock->getObjects();
|
||||
$this->assertCount(count($objects["service"]), $result);
|
||||
|
||||
}
|
||||
|
||||
public function testSimpleHostSelect()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
|
||||
$result = & $query->from("hosts")->getResult();
|
||||
$objects = $readerMock->getObjects();
|
||||
$this->assertCount(count($objects["host"]), $result);
|
||||
|
||||
}
|
||||
|
||||
public function testLimit()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
|
||||
$result = &$query->from("services")->limit(2)->getResult();
|
||||
$this->assertCount(2, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testOffset()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
|
||||
$result = & $query->from("services")->limit(2, 4)->getResult();
|
||||
$this->assertCount(2, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testGroupByColumn()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$result = &$query->from("services")->groupByColumns("numeric_val")->getResult();
|
||||
$this->assertCount(3,$result);
|
||||
foreach($result as $value) {
|
||||
$this->assertTrue(isset($value->count));
|
||||
$this->assertTrue(isset($value->columns));
|
||||
$this->assertEquals(2,$value->count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testOrderedGroupByColumn()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$result = &$query->from("services")->order('numeric_val ASC')->groupByColumns("numeric_val")->getResult();
|
||||
$this->assertCount(3,$result);
|
||||
$lastIdx = ~PHP_INT_MAX;
|
||||
foreach($result as $sstatus) {
|
||||
$this->assertTrue(isset($sstatus->count));
|
||||
$this->assertTrue(isset($sstatus->columns));
|
||||
$this->assertEquals(2,$sstatus->count);
|
||||
$this->assertGreaterThanOrEqual($lastIdx,$sstatus->columns->numeric_val);
|
||||
$lastIdx = $sstatus->columns->numeric_val;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testOrderSingleColumnASC()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$result = &$query->from("services")->order('numeric_val ASC')->getResult();
|
||||
$lastIdx = ~PHP_INT_MAX;
|
||||
foreach($result as $sstatus) {
|
||||
$this->assertGreaterThanOrEqual($lastIdx,$sstatus->numeric_val);
|
||||
$lastIdx = $sstatus->numeric_val;
|
||||
}
|
||||
}
|
||||
|
||||
public function testOrderSingleColumnDESC()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$result = &$query->from("services")->order('numeric_val DESC')->getResult();
|
||||
$lastIdx = PHP_INT_MAX;
|
||||
foreach($result as $sstatus) {
|
||||
$this->assertLessThanOrEqual($lastIdx,$sstatus->numeric_val);
|
||||
$lastIdx = $sstatus->numeric_val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Integration test for query and Expression/Group objects.
|
||||
* This is not a unit test, but checks if the 'where' filter really works
|
||||
*/
|
||||
public function testQueryIntegration() {
|
||||
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$result = &$query->from("services")->where('numeric_val = ?',array(1))->getResult();
|
||||
foreach($result as $testresult) {
|
||||
$this->assertEquals($testresult->numeric_val,1);
|
||||
}
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$result = &$query->from("services")->where('numeric_val < ? OR numeric_val = ?',array(2,3))->getResult();
|
||||
foreach($result as $testresult) {
|
||||
$this->assertNotEquals($testresult->numeric_val,2);
|
||||
}
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$result = &$query->from("services")->where('numeric_val < ? OR numeric_val = ?',array(2,3))->where("numeric_val = ?",array(1))->getResult();
|
||||
foreach($result as $testresult) {
|
||||
$this->assertEquals($testresult->numeric_val,1);
|
||||
}
|
||||
}
|
||||
|
||||
private function getServiceTestReader()
|
||||
{
|
||||
$readerMock = new ReaderMock(array(
|
||||
"host" => array(
|
||||
"hosta" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"numeric_val" => 0,
|
||||
"services" => array(0, 1, 2)
|
||||
),
|
||||
"hostb" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"numeric_val" => 0,
|
||||
"services" => array(3, 4, 5)
|
||||
)
|
||||
),
|
||||
"service" => array(
|
||||
"hosta;service1" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"service_description" => "service1",
|
||||
"numeric_val" => 1
|
||||
),
|
||||
"hosta;service2" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"service_description" => "service2",
|
||||
"numeric_val" => 3
|
||||
),
|
||||
"hosta;service3" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"service_description" => "service3",
|
||||
"numeric_val" => 2
|
||||
),
|
||||
"hostb;service1" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service1",
|
||||
"numeric_val" => 1
|
||||
),
|
||||
"hostb;service2" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service2",
|
||||
"numeric_val" => 3
|
||||
),
|
||||
"hostb;service3" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service3",
|
||||
"numeric_val" => 2
|
||||
)
|
||||
)
|
||||
));
|
||||
return $readerMock;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
require_once("../library/Icinga/Protocol/Statusdat/IReader.php");
|
||||
|
||||
use Icinga\Protocol\Statusdat\IReader;
|
||||
|
||||
class ReaderMock implements IReader
|
||||
{
|
||||
private $objects;
|
||||
private $indices;
|
||||
|
||||
public function __construct(array $objects = array())
|
||||
{
|
||||
$this->objects = $objects;
|
||||
}
|
||||
|
||||
public function getState()
|
||||
{
|
||||
return array(
|
||||
"objects" => $this->objects,
|
||||
"indices" => $this->indices
|
||||
);
|
||||
}
|
||||
|
||||
public function getObjects()
|
||||
{
|
||||
return $this->objects;
|
||||
}
|
||||
|
||||
public function __call($arg1,$arg2) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function getObjectByName($type, $idx)
|
||||
{
|
||||
if (isset($this->objects[$type]) && isset($this->objects[$type][$idx]))
|
||||
return $this->objects[$type][$idx];
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
require_once("../library/Icinga/Protocol/Statusdat/IReader.php");
|
||||
require_once("../library/Icinga/Protocol/Statusdat/Reader.php");
|
||||
require_once("../library/Icinga/Exception/ConfigurationError.php");
|
||||
|
||||
use Icinga\Protocol\Statusdat\Reader as Reader;
|
||||
define("APPLICATION_PATH","./"); // TODO: test boostrap
|
||||
/**
|
||||
*
|
||||
* Test class for Reader
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class ConfigMock {
|
||||
function __construct($data) {
|
||||
foreach($data as $key=>$val)
|
||||
$this->$key = $val;
|
||||
}
|
||||
function get($attr) {
|
||||
return $this->$attr;
|
||||
}
|
||||
}
|
||||
|
||||
class ParserMock {
|
||||
|
||||
public $runtime = array();
|
||||
public $objects = array();
|
||||
public function parseObjectsFile() {
|
||||
return $this->objects;
|
||||
}
|
||||
public function parseRuntimeState() {
|
||||
return $this->runtime;
|
||||
}
|
||||
|
||||
public function getRuntimeState() {
|
||||
return $this->runtime;
|
||||
}
|
||||
}
|
||||
|
||||
require("Zend/Cache.php");
|
||||
class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testFileCaching() {
|
||||
$parser = new ParserMock();
|
||||
@system("rm ./tmp/zend_cache*");
|
||||
$parser->runtime = array("host"=>array(
|
||||
"test" => (object) array(
|
||||
"host_name" => "test"
|
||||
)
|
||||
));
|
||||
$object_file = tempnam("./dir","object");
|
||||
$status_file = tempnam("./dir","status");
|
||||
$reader = new Reader(new ConfigMock(array(
|
||||
"cache_path" => "./tmp",
|
||||
"objects_file" => $object_file,
|
||||
"status_file" => $status_file
|
||||
)),$parser);
|
||||
unlink($object_file);
|
||||
unlink($status_file);
|
||||
$this->assertTrue(file_exists("./tmp/zend_cache---objects".md5($object_file)));
|
||||
$this->assertTrue(file_exists("./tmp/zend_cache---state".md5($object_file)));
|
||||
system("rm ./tmp/zend_cache*");
|
||||
}
|
||||
public function testEmptyFileException() {
|
||||
$this->setExpectedException("Icinga\Exception\ConfigurationError");
|
||||
$parser = new ParserMock();
|
||||
$reader = new Reader(new ConfigMock(array(
|
||||
"cache_path" => "./tmp",
|
||||
"objects_file" => "",
|
||||
"status_file" => "",
|
||||
)),$parser);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
|
||||
require_once("../library/Icinga/Protocol/Statusdat/RuntimeStateContainer.php");
|
||||
|
||||
class RuntimestatecontainerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for RuntimeStateContainer::__get()
|
||||
*
|
||||
**/
|
||||
public function testPropertyResolving()
|
||||
{
|
||||
|
||||
$container = new \Icinga\Protocol\Statusdat\RuntimeStateContainer("
|
||||
host_name=test host
|
||||
current_state=0
|
||||
plugin_output=test 1234 test test
|
||||
test=dont read
|
||||
");
|
||||
$container->test = "test123";
|
||||
$this->assertEquals("test host",$container->host_name);
|
||||
$this->assertEquals($container->test,"test123");
|
||||
$this->assertEquals(0,$container->current_state);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Web\ActionController;
|
||||
use Icinga\Web\ActionController as Action;
|
||||
|
||||
require_once('Zend/Controller/Action.php');
|
||||
require_once('../library/Icinga/Web/ActionController.php');
|
||||
|
||||
/**
|
||||
* This is not a nice hack, but doesn't affect the behaviour of
|
||||
* the tested methods, allowing us to avoid bootstrapping
|
||||
* the request/response System for every test
|
||||
*
|
||||
* Class ActionTestWrap
|
||||
* @package Tests\Icinga\Mvc\Controller
|
||||
*/
|
||||
class ActionTestWrap extends Action {
|
||||
private $args;
|
||||
public function __construct(\Zend_Controller_Request_Abstract $request = null,
|
||||
\Zend_Controller_Response_Abstract $response = null, array $invokeArgs = array())
|
||||
{}
|
||||
|
||||
public function setArguments($args) {
|
||||
$this->args = $args;
|
||||
}
|
||||
|
||||
protected function _getParam($paramName, $default = null) {
|
||||
if(isset($this->args[$paramName]))
|
||||
return $this->args[$paramName];
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
class ActionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSeedGeneration()
|
||||
{
|
||||
$action = new ActionTestWrap();
|
||||
list($seed1,$token1) = $action->getSeedTokenPair(600,"test");
|
||||
list($seed2,$token2) = $action->getSeedTokenPair(600,"test");
|
||||
list($seed3,$token3) = $action->getSeedTokenPair(600,"test");
|
||||
$this->assertTrue($seed1 != $seed2 && $seed2 != $seed3 && $seed1 != $seed3);
|
||||
$this->assertTrue($token1 != $token2 && $token2 != $token3 && $token1 != $token3);
|
||||
}
|
||||
|
||||
public function testSeedValidation()
|
||||
{
|
||||
$action = new ActionTestWrap();
|
||||
list($seed,$token) = $action->getSeedTokenPair(600,"test");
|
||||
$action->setArguments(array(
|
||||
"seed" => $seed,
|
||||
"token" => $token
|
||||
));
|
||||
$this->assertTrue($action->hasValidToken(600,"test"));
|
||||
$this->assertFalse($action->hasValidToken(600,"test2"));
|
||||
$action->setArguments(array(
|
||||
"seed" => $seed."ds",
|
||||
"token" => $token
|
||||
));
|
||||
$this->assertFalse($action->hasValidToken(600,"test"));
|
||||
$action->setArguments(array(
|
||||
"seed" => $seed,
|
||||
"token" => $token."afs"
|
||||
));
|
||||
$this->assertFalse($action->hasValidToken(600,"test"));
|
||||
}
|
||||
|
||||
public function testMaxAge()
|
||||
{
|
||||
$action = new ActionTestWrap();
|
||||
list($seed,$token) = $action->getSeedTokenPair(1,"test");
|
||||
$action->setArguments(array(
|
||||
"seed" => $seed,
|
||||
"token" => $token
|
||||
));
|
||||
$this->assertTrue($action->hasValidToken(1,"test"));
|
||||
sleep(1);
|
||||
$this->assertFalse($action->hasValidToken(1,"test"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Web;
|
||||
/**
|
||||
*
|
||||
* Test class for Hook
|
||||
* Created Fri, 22 Mar 2013 09:44:40 +0000
|
||||
*
|
||||
**/
|
||||
require_once("../library/Icinga/Exception/ProgrammingError.php");
|
||||
require_once("../library/Icinga/Web/Hook.php");
|
||||
|
||||
use Icinga\Web\Hook as Hook;
|
||||
class Base
|
||||
{
|
||||
}
|
||||
|
||||
class TestHookImplementation extends Base
|
||||
{
|
||||
}
|
||||
|
||||
class TestBadHookImplementation
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
class HookTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Hook::Has()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testHas()
|
||||
{
|
||||
Hook::clean();
|
||||
$this->assertFalse(Hook::has("a"));
|
||||
$this->assertFalse(Hook::has("a","b"));
|
||||
|
||||
Hook::register("a","b","c");
|
||||
$this->assertTrue(Hook::has("a"));
|
||||
$this->assertTrue(Hook::has("a","b"));
|
||||
Hook::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Hook::CreateInstance()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testCreateInstance()
|
||||
{
|
||||
Hook::clean();
|
||||
Hook::$BASE_NS = "Tests\\Icinga\\Web\\";
|
||||
Hook::register("Base","b","Tests\\Icinga\\Web\\TestHookImplementation");
|
||||
$this->assertInstanceOf("Tests\\Icinga\\Web\\TestHookImplementation",Hook::createInstance("Base","b"));
|
||||
Hook::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Hook::CreateInstance()
|
||||
* Note: This method is static!
|
||||
*
|
||||
*
|
||||
**/
|
||||
public function testCreateInvalidInstance()
|
||||
{
|
||||
$this->setExpectedException('\Icinga\Exception\ProgrammingError');
|
||||
Hook::clean();
|
||||
Hook::$BASE_NS = "Tests\\Icinga\\Web\\";
|
||||
Hook::register("Base","b","Tests\\Icinga\\Web\\TestBadHookImplementation");
|
||||
Hook::createInstance("Base","b");
|
||||
Hook::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Hook::All()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testAll()
|
||||
{
|
||||
Hook::clean();
|
||||
Hook::$BASE_NS = "Tests\\Icinga\\Web\\";
|
||||
Hook::register("Base","a","Tests\\Icinga\\Web\\TestHookImplementation");
|
||||
Hook::register("Base","b","Tests\\Icinga\\Web\\TestHookImplementation");
|
||||
Hook::register("Base","c","Tests\\Icinga\\Web\\TestHookImplementation");
|
||||
$this->assertCount(3,Hook::all("Base"));
|
||||
foreach(Hook::all("Base") as $instance) {
|
||||
$this->assertInstanceOf("Tests\\Icinga\\Web\\TestHookImplementation",$instance);
|
||||
}
|
||||
Hook::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Hook::First()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testFirst()
|
||||
{
|
||||
Hook::clean();
|
||||
Hook::$BASE_NS = "Tests\\Icinga\\Web\\";
|
||||
Hook::register("Base","a","Tests\\Icinga\\Web\\TestHookImplementation");
|
||||
Hook::register("Base","b","Tests\\Icinga\\Web\\TestHookImplementation");
|
||||
Hook::register("Base","c","Tests\\Icinga\\Web\\TestHookImplementation");
|
||||
|
||||
$this->assertInstanceOf("Tests\\Icinga\\Web\\TestHookImplementation",Hook::first("Base"));
|
||||
Hook::clean();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Web\Paginator\ScrollingStyle;
|
||||
/**
|
||||
*
|
||||
* Test class for Slidingwithborder
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class SlidingwithborderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for SlidingWithBorder::GetPages()
|
||||
*
|
||||
**/
|
||||
public function testGetPages()
|
||||
{
|
||||
$this->markTestIncomplete('testGetPages is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue