/usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php is in icingaweb2-module-monitoring 2.1.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | <?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
class NotificationhistoryQuery extends IdoQuery
{
protected $columnMap = array(
'history' => array(
'state_time' => 'n.start_time',
'timestamp' => 'UNIX_TIMESTAMP(n.start_time)',
'raw_timestamp' => 'n.start_time',
'object_id' => 'n.object_id',
'type' => "('notify')",
'state' => 'n.state',
'state_type' => '(NULL)',
'output' => null,
'attempt' => '(NULL)',
'max_attempts' => '(NULL)',
'host' => 'o.name1 COLLATE latin1_general_ci',
'service' => 'o.name2 COLLATE latin1_general_ci',
'host_name' => 'o.name1',
'service_description' => 'o.name2',
'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END"
)
);
public function whereToSql($col, $sign, $expression)
{
if ($col === 'UNIX_TIMESTAMP(n.start_time)') {
return 'n.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
} else {
return parent::whereToSql($col, $sign, $expression);
}
}
protected function joinBaseTables()
{
switch ($this->ds->getDbType()) {
case 'mysql':
$concattedContacts = "GROUP_CONCAT(co.name1 ORDER BY co.name1 SEPARATOR ', ') COLLATE latin1_general_ci";
break;
case 'pgsql':
// TODO: Find a way to order the contact alias list:
$concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(co.name1), ', ')";
break;
case 'oracle':
// TODO: This is only valid for Oracle >= 11g Release 2
$concattedContacts = "LISTAGG(co.name1, ', ') WITHIN GROUP (ORDER BY co.name1)";
// Alternatives:
//
// RTRIM(XMLAGG(XMLELEMENT(e, column_name, ',').EXTRACT('//text()')),
//
// not supported and not documented but works since 10.1,
// however it is NOT always present:
// WM_CONCAT(c.alias)
break;
}
$this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || n.output)";
$this->select->from(
array('o' => $this->prefix . 'objects'),
array()
)->join(
array('n' => $this->prefix . 'notifications'),
'o.' . $this->object_id . ' = n.' . $this->object_id . ' AND o.is_active = 1',
array()
)->join(
array('cn' => $this->prefix . 'contactnotifications'),
'cn.notification_id = n.notification_id',
array()
)->joinLeft(
array('co' => $this->prefix . 'objects'),
'cn.contact_object_id = co.object_id',
array()
)->joinLeft(
array('c' => $this->prefix . 'contacts'),
'co.object_id = c.contact_object_id',
array()
)->group('cn.notification_id');
// TODO: hmmmm...
if ($this->ds->getDbType() === 'pgsql') {
$this->select->group('n.object_id')
->group('n.start_time')
->group('n.output')
->group('n.state')
->group('o.objecttype_id');
}
$this->joinedVirtualTables = array('history' => true);
}
}
|