1 <?php 2 3 /* 4 +----------------------------------------------------------------------------------+ 5 | (c) 2006-2007 - The Mail Network (UK) | 6 | NetServe Applications Development | 7 |----------------------------------------------------------------------------------| 8 | File Name: s3_class.inc.php | 9 | Description: Class templates for hosts/services/comments | 10 |----------------------------------------------------------------------------------| 11 | This application is distributed under the terms of the Creative Commons Public | 12 | license. Your copy of the license is called 'LICENSE.txt' and is in the root of | 13 | the application distribution files. | 14 | | 15 | You may also view the license online at the following URLs: | 16 | | 17 | http://creativecommons.org/licenses/by-sa/2.5/ | 18 | http://creativecommons.org/licenses/by-sa/2.5/legalcode | 19 | | 20 | All work on this application is the copyright of the author (Andy Shellam) and | 21 | the author's company (Andy Shellam Productions) - created in the year 2006, and | 22 | the author retains the copyright until further notice or when the application is | 23 | terminated/discontinued. | 24 | | 25 | Please respect the work that has gone into this application - don't charge for | 26 | re-distribution of this application, and don't pass it off as your own work. You | 27 | may charge for commercial services relating to this application, but not for the | 28 | sale of the application itself, and you must provide all source code, without | 29 | using technologies such as encryption/encoding. | 30 | | 31 | Thank you for using Nagios Looking Glass! - Andy | 32 +----------------------------------------------------------------------------------+ 33 */ 34 35 class S3_NagiosPoller 36 { 37 /* 38 * S3_NagiosPoller() 39 * Holds all details of hosts/services and metrics of Nagios 40 */ 41 42 // Core Poller Info 43 public $Poller_Version = "1.0.4/S3"; 44 public $Nagios_Hostname; 45 public $Nagios_Version; 46 public $Nagios_FeedUpdated; 47 public $NLG_FeedSource = "live"; 48 public $NLG_CachedTime; 49 public $NLG_Index;50 51 // Filtering/Grouping status 52 public $Nagios_HostCount = 0; 53 public $Nagios_HostFilterCount = 0; 54 public $Nagios_ServiceCount = 0; 55 public $FilterApplied = "--ALL--"; 56 public $CurrentFilter; 57 public $HostGroups; 58 public $CurrentGroup; 59 60 // Network Status 61 public $Network_ServerOK; 62 public $Network_ServerDown; 63 public $Network_ServerNetworkError; 64 public $Network_ServerDegradedMetrics; 65 public $Network_ServerUnknown; 66 public $Network_MetricOK; 67 public $Network_MetricWarn; 68 public $Network_MetricFail; 69 public $Network_MetricUnknown; 70 71 // Data Objects 72 public $Hosts; 73 // as of 1.0.0 - $Services is now part of the host class as it's host-specific 74 public $Comments; 75 76 // Error Info 77 public $LastPollerError; 78 79 public function Init($NagiosHostInConfig = "") 80 { 81 /* 82 * Init() 83 * Initialise the class - if a hostname is given, use it, if not, 84 * look it up from the system 85 */ 86 87 if (strlen($NagiosHostInConfig) == 0) { 88 $this->Nagios_Hostname = trim(`hostname`); 89 } else { 90 $this->Nagios_Hostname = trim($NagiosHostInConfig); 91 } 92 93 $this->Hosts = Array(); 94 $this->Comments = Array(); 95 96 return true; 97 } 98 99 public function CreateErrorToken($ErrorDescription) 100 { 101 /* 102 * CreateErrorToken() 103 * Create an output return token with error information 104 */ 105 106 $ErrorText = base64_encode($ErrorDescription); 107 $ErrorTextChecksum = md5($ErrorText); 108 echo "**NLGPOLLER!!" . $this->Poller_Version . "!!" . $this->Nagios_Hostname . "!!FALSE!!" . $ErrorText . "!!" . $ErrorTextChecksum . "!!NLGPOLLE R**"; 109 exit(1); 110 } 111 112 public function CreateOutputToken() 113 { 114 /* 115 * CreateErrorToken() 116 * Create an output return token with all current data 117 */ 118 119 $OutputText = base64_encode(serialize($this)); 120 $OutputTextChecksum = md5($OutputText); 121 echo "**NLGPOLLER!!" . $this->Poller_Version . "!!" . $this->Nagios_Hostname . "!!TRUE!!" . $OutputText . "!!" . $OutputTextChecksum . "!!NLGPOLL ER**"; 122 exit(0); 123 } 124 } 125 126 class S3_NagiosHost 127 { 128 /* 129 * S3_NagiosHost() 130 * The host template class 131 */ 132 133 public $HostID; 134 public $GroupID; 135 public $HostName; 136 public $HostStatus; 137 public $LastCheck; 138 public $NextCheck; 139 public $CheckResult; 140 public $HostServices; 141 public $ServiceCount_Total; 142 public $ServiceCount_OK; 143 public $ServiceCount_Warn; 143 public $ServiceCount_Warn; 144 public $ServiceCount_Fail; 145 public $ServiceCount_Unknown; 146 public $RequiredInFilter = true; 147 public $RequiredInGroup = true; 148 } 149 150 class S3_NagiosService 151 { 152 /* 153 * S3_NagiosService() 154 * The service template class 155 */ 156 157 public $ServiceID; 158 public $HostID; 159 public $ServiceName; 160 public $ServiceStatus; 161 public $LastCheck; 162 public $NextCheck; 163 public $CheckResult; 164 } 165 166 class S3_NagiosComment 167 { 168 /* 169 * S3_NagiosComment() 170 * Any comment starting with NLG# is passed back to the client 171 */ 172 173 // Nagios host comments 174 175 public $CommentID; 176 public $Type; 177 public $Host; 178 public $Service; 179 public $EntryTime; 180 public $Author; 181 public $CommentText; 182 } 183 184 class S3_NetworkFilter 185 { 186 public $FilterDisplayText; 187 private $FilterHostsToInclude; 188 189 function Create($DisplayText) 190 { 191 /* 143,27-28