2013-07-12 08:33:17 -04:00
|
|
|
<?php
|
2016-02-08 09:41:00 -05:00
|
|
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
2013-07-12 08:33:17 -04:00
|
|
|
|
2013-08-20 09:32:25 -04:00
|
|
|
namespace Icinga\Module\Monitoring\Object;
|
2013-07-12 08:33:17 -04:00
|
|
|
|
2022-05-03 04:37:17 -04:00
|
|
|
use Icinga\Data\Filter\FilterEqual;
|
2023-08-16 10:58:07 -04:00
|
|
|
use Icinga\Module\Monitoring\DataView\Servicestatus;
|
2014-09-16 12:44:44 -04:00
|
|
|
use InvalidArgumentException;
|
2014-11-11 10:29:07 -05:00
|
|
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
2013-07-12 08:33:17 -04:00
|
|
|
|
2014-09-12 04:17:46 -04:00
|
|
|
/**
|
2015-05-28 08:21:05 -04:00
|
|
|
* An Icinga service
|
2014-09-12 04:17:46 -04:00
|
|
|
*/
|
2014-09-04 07:07:03 -04:00
|
|
|
class Service extends MonitoredObject
|
2013-07-12 08:33:17 -04:00
|
|
|
{
|
2014-09-16 12:44:44 -04:00
|
|
|
/**
|
|
|
|
|
* Service state 'OK'
|
|
|
|
|
*/
|
|
|
|
|
const STATE_OK = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Service state 'WARNING'
|
|
|
|
|
*/
|
|
|
|
|
const STATE_WARNING = 1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Service state 'CRITICAL'
|
|
|
|
|
*/
|
|
|
|
|
const STATE_CRITICAL = 2;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Service state 'UNKNOWN'
|
|
|
|
|
*/
|
|
|
|
|
const STATE_UNKNOWN = 3;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Service state 'PENDING'
|
|
|
|
|
*/
|
|
|
|
|
const STATE_PENDING = 99;
|
|
|
|
|
|
2014-09-12 04:17:46 -04:00
|
|
|
/**
|
|
|
|
|
* Type of the Icinga service
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public $type = self::TYPE_SERVICE;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prefix of the Icinga service
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-03-09 14:29:23 -04:00
|
|
|
public $prefix = 'service_';
|
2013-07-12 08:33:17 -04:00
|
|
|
|
2014-09-12 04:17:46 -04:00
|
|
|
/**
|
2014-09-16 12:44:44 -04:00
|
|
|
* Host the service is running on
|
2014-09-12 04:17:46 -04:00
|
|
|
*
|
2014-09-16 12:44:44 -04:00
|
|
|
* @var Host
|
2014-09-12 04:17:46 -04:00
|
|
|
*/
|
|
|
|
|
protected $host;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Service name
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new service
|
|
|
|
|
*
|
2015-01-20 10:11:41 -05:00
|
|
|
* @param MonitoringBackend $backend Backend to fetch service information from
|
|
|
|
|
* @param string $host Hostname the service is running on
|
|
|
|
|
* @param string $service Service name
|
2014-09-12 04:17:46 -04:00
|
|
|
*/
|
2014-11-11 10:29:07 -05:00
|
|
|
public function __construct(MonitoringBackend $backend, $host, $service)
|
2014-03-04 07:59:26 -05:00
|
|
|
{
|
2014-09-12 04:17:46 -04:00
|
|
|
parent::__construct($backend);
|
2014-09-16 12:44:44 -04:00
|
|
|
$this->host = new Host($backend, $host);
|
2014-09-12 04:17:46 -04:00
|
|
|
$this->service = $service;
|
2014-03-04 07:59:26 -05:00
|
|
|
}
|
|
|
|
|
|
2014-09-12 04:17:46 -04:00
|
|
|
/**
|
2014-09-16 12:44:44 -04:00
|
|
|
* Get the host the service is running on
|
2014-09-12 04:17:46 -04:00
|
|
|
*
|
2014-09-16 12:44:44 -04:00
|
|
|
* @return Host
|
2014-09-12 04:17:46 -04:00
|
|
|
*/
|
|
|
|
|
public function getHost()
|
2013-07-12 08:33:17 -04:00
|
|
|
{
|
2014-09-12 04:17:46 -04:00
|
|
|
return $this->host;
|
2013-07-12 08:33:17 -04:00
|
|
|
}
|
2013-09-04 12:27:16 -04:00
|
|
|
|
2014-09-12 04:17:46 -04:00
|
|
|
/**
|
|
|
|
|
* Get the service name
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2014-09-16 12:44:44 -04:00
|
|
|
public function getName()
|
2013-07-12 08:33:17 -04:00
|
|
|
{
|
2014-09-12 04:17:46 -04:00
|
|
|
return $this->service;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the data view
|
|
|
|
|
*
|
2023-08-16 10:58:07 -04:00
|
|
|
* @return Servicestatus
|
2014-09-12 04:17:46 -04:00
|
|
|
*/
|
|
|
|
|
protected function getDataView()
|
|
|
|
|
{
|
2015-06-12 08:42:49 -04:00
|
|
|
return $this->backend->select()->from('servicestatus', array(
|
2015-08-26 04:52:56 -04:00
|
|
|
'instance_name',
|
2015-10-28 07:08:04 -04:00
|
|
|
'host_attempt',
|
2015-05-19 12:08:26 -04:00
|
|
|
'host_icon_image',
|
2015-05-21 08:59:12 -04:00
|
|
|
'host_icon_image_alt',
|
2015-03-10 09:17:09 -04:00
|
|
|
'host_acknowledged',
|
|
|
|
|
'host_active_checks_enabled',
|
2014-05-20 18:19:26 -04:00
|
|
|
'host_address',
|
2015-07-16 04:35:28 -04:00
|
|
|
'host_address6',
|
2015-03-10 09:17:09 -04:00
|
|
|
'host_alias',
|
|
|
|
|
'host_display_name',
|
2014-05-20 18:19:26 -04:00
|
|
|
'host_handled',
|
|
|
|
|
'host_in_downtime',
|
2016-11-21 04:26:35 -05:00
|
|
|
'host_is_flapping',
|
2015-03-10 09:17:09 -04:00
|
|
|
'host_last_state_change',
|
|
|
|
|
'host_name',
|
2014-05-20 18:19:26 -04:00
|
|
|
'host_notifications_enabled',
|
|
|
|
|
'host_passive_checks_enabled',
|
2015-03-10 09:17:09 -04:00
|
|
|
'host_state',
|
2015-10-28 07:08:04 -04:00
|
|
|
'host_state_type',
|
2015-05-19 12:08:26 -04:00
|
|
|
'service_icon_image',
|
2015-05-21 08:59:12 -04:00
|
|
|
'service_icon_image_alt',
|
2015-03-10 09:17:09 -04:00
|
|
|
'service_acknowledged',
|
2015-09-03 10:23:27 -04:00
|
|
|
'service_acknowledgement_type',
|
2015-03-10 09:17:09 -04:00
|
|
|
'service_action_url',
|
2014-05-20 18:19:26 -04:00
|
|
|
'service_active_checks_enabled',
|
|
|
|
|
'service_active_checks_enabled_changed',
|
2015-03-10 09:17:09 -04:00
|
|
|
'service_attempt',
|
|
|
|
|
'service_check_command',
|
2014-06-17 09:14:00 -04:00
|
|
|
'service_check_execution_time',
|
2018-07-18 09:42:34 -04:00
|
|
|
'service_check_interval',
|
2014-06-17 09:14:00 -04:00
|
|
|
'service_check_latency',
|
2015-03-10 09:17:09 -04:00
|
|
|
'service_check_source',
|
2015-09-14 06:05:15 -04:00
|
|
|
'service_check_timeperiod',
|
2015-03-10 09:17:09 -04:00
|
|
|
'service_current_notification_number',
|
|
|
|
|
'service_description',
|
|
|
|
|
'service_display_name',
|
2014-05-20 18:19:26 -04:00
|
|
|
'service_event_handler_enabled',
|
|
|
|
|
'service_event_handler_enabled_changed',
|
|
|
|
|
'service_flap_detection_enabled',
|
|
|
|
|
'service_flap_detection_enabled_changed',
|
2015-03-10 09:17:09 -04:00
|
|
|
'service_handled',
|
|
|
|
|
'service_in_downtime',
|
|
|
|
|
'service_is_flapping',
|
2015-03-12 19:26:02 -04:00
|
|
|
'service_is_reachable',
|
2015-03-10 09:17:09 -04:00
|
|
|
'service_last_check',
|
|
|
|
|
'service_last_notification',
|
|
|
|
|
'service_last_state_change',
|
|
|
|
|
'service_long_output',
|
|
|
|
|
'service_next_check',
|
2015-09-04 10:22:16 -04:00
|
|
|
'service_next_update',
|
2015-05-26 09:47:01 -04:00
|
|
|
'service_notes',
|
2015-03-10 09:17:09 -04:00
|
|
|
'service_notes_url',
|
|
|
|
|
'service_notifications_enabled',
|
|
|
|
|
'service_notifications_enabled_changed',
|
|
|
|
|
'service_obsessing',
|
|
|
|
|
'service_obsessing_changed',
|
|
|
|
|
'service_output',
|
|
|
|
|
'service_passive_checks_enabled',
|
|
|
|
|
'service_passive_checks_enabled_changed',
|
|
|
|
|
'service_percent_state_change',
|
|
|
|
|
'service_perfdata',
|
2015-03-10 09:11:50 -04:00
|
|
|
'service_process_perfdata' => 'service_process_performance_data',
|
2015-03-10 09:17:09 -04:00
|
|
|
'service_state',
|
|
|
|
|
'service_state_type'
|
2014-09-12 04:17:46 -04:00
|
|
|
))
|
2022-05-03 04:37:17 -04:00
|
|
|
->whereEx(new FilterEqual('host_name', '=', $this->host->getName()))
|
|
|
|
|
->whereEx(new FilterEqual('service_description', '=', $this->service));
|
2014-09-04 06:54:52 -04:00
|
|
|
}
|
2014-09-16 12:44:44 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-10-29 08:36:24 -04:00
|
|
|
* Get the optional translated textual representation of a service state
|
2014-09-16 12:44:44 -04:00
|
|
|
*
|
2014-10-29 08:36:24 -04:00
|
|
|
* @param int $state
|
|
|
|
|
* @param bool $translate
|
2014-09-16 12:44:44 -04:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
* @throws InvalidArgumentException If the service state is not valid
|
|
|
|
|
*/
|
2014-10-29 08:36:24 -04:00
|
|
|
public static function getStateText($state, $translate = false)
|
2014-09-16 12:44:44 -04:00
|
|
|
{
|
2014-10-29 08:36:24 -04:00
|
|
|
$translate = (bool) $translate;
|
2014-09-16 12:44:44 -04:00
|
|
|
switch ((int) $state) {
|
|
|
|
|
case self::STATE_OK:
|
2015-01-22 08:36:22 -05:00
|
|
|
$text = $translate ? mt('monitoring', 'OK') : 'ok';
|
2014-09-16 12:44:44 -04:00
|
|
|
break;
|
|
|
|
|
case self::STATE_WARNING:
|
2015-01-22 08:36:22 -05:00
|
|
|
$text = $translate ? mt('monitoring', 'WARNING') : 'warning';
|
2014-09-16 12:44:44 -04:00
|
|
|
break;
|
|
|
|
|
case self::STATE_CRITICAL:
|
2015-01-22 08:36:22 -05:00
|
|
|
$text = $translate ? mt('monitoring', 'CRITICAL') : 'critical';
|
2014-09-16 12:44:44 -04:00
|
|
|
break;
|
|
|
|
|
case self::STATE_UNKNOWN:
|
2015-01-22 08:36:22 -05:00
|
|
|
$text = $translate ? mt('monitoring', 'UNKNOWN') : 'unknown';
|
2014-09-16 12:44:44 -04:00
|
|
|
break;
|
|
|
|
|
case self::STATE_PENDING:
|
2015-01-22 08:36:22 -05:00
|
|
|
$text = $translate ? mt('monitoring', 'PENDING') : 'pending';
|
2014-09-16 12:44:44 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
2023-06-22 03:57:40 -04:00
|
|
|
throw new InvalidArgumentException(sprintf('Invalid service state \'%s\'', $state));
|
2014-09-16 12:44:44 -04:00
|
|
|
}
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
2015-05-26 09:47:01 -04:00
|
|
|
|
|
|
|
|
public function getNotesUrls()
|
|
|
|
|
{
|
2015-05-28 08:58:16 -04:00
|
|
|
return $this->resolveAllStrings(
|
|
|
|
|
MonitoredObject::parseAttributeUrls($this->service_notes_url)
|
|
|
|
|
);
|
2015-05-26 09:47:01 -04:00
|
|
|
}
|
2013-07-12 08:33:17 -04:00
|
|
|
}
|