From 9465c3ffb6064b12fc32fab466ba4baf4d5a5600 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Wed, 27 Aug 2014 16:13:25 +0200 Subject: [PATCH 1/2] Show/Contact: Add commands to view Create a new command query and join contact information into. refs #4804 --- .../controllers/ShowController.php | 25 ++++++-- .../views/scripts/show/contact.phtml | 21 ++++--- .../Backend/Ido/Query/CommandQuery.php | 60 +++++++++++++++++++ .../library/Monitoring/DataView/Command.php | 28 +++++++++ 4 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/CommandQuery.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Command.php diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index 55b57cd52..19c1b7bef 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -108,13 +108,15 @@ class Monitoring_ShowController extends Controller public function contactAction() { - $contact = $this->getParam('contact'); - if (! $contact) { + $contactName = $this->getParam('contact'); + + if (! $contactName) { throw new Zend_Controller_Action_Exception( $this->translate('The parameter `contact\' is required'), 404 ); } + $query = $this->backend->select()->from('contact', array( 'contact_name', 'contact_id', @@ -135,9 +137,22 @@ class Monitoring_ShowController extends Controller 'contact_notify_host_flapping', 'contact_notify_host_downtime', )); - $query->where('contact_name', $contact); - $this->view->contacts = $query->paginate(); - $this->view->contact_name = $contact; + + $query->where('contact_name', $contactName); + + $contact = $query->getQuery()->fetchRow(); + + if ($contact) { + $commands = $this->backend->select()->from('command', array( + 'command_line', + 'command_name' + ))->where('contact_id', $contact->contact_id); + + $this->view->commands = $commands->paginate(); + } + + $this->view->contact = $contact; + $this->view->contactName = $contactName; } /** diff --git a/modules/monitoring/application/views/scripts/show/contact.phtml b/modules/monitoring/application/views/scripts/show/contact.phtml index a7b691eb4..fff03a106 100644 --- a/modules/monitoring/application/views/scripts/show/contact.phtml +++ b/modules/monitoring/application/views/scripts/show/contact.phtml @@ -2,7 +2,7 @@ $contactHelper = $this->getHelper('ContactFlags'); ?>
- + @@ -45,12 +45,15 @@ $contactHelper = $this->getHelper('ContactFlags');
- + +

translate('Commands'); ?>:

+ + + + translate('No such contact'); ?>: +
diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommandQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommandQuery.php new file mode 100644 index 000000000..664cb3576 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommandQuery.php @@ -0,0 +1,60 @@ + array( + 'command_id' => 'c.command_id', + 'command_instance_id' => 'c.instance_id', + 'command_config_type' => 'c.config_type', + 'command_line' => 'c.command_line', + 'command_name' => 'co.name1' + ), + + 'contacts' => array( + 'contact_id' => 'con.contact_id', + 'contact_alias' => 'con.contact_alias' + ) + ); + + /** + * Fetch basic information about commands + */ + protected function joinBaseTables() + { + $this->select->from( + array('c' => $this->prefix . 'commands'), + array() + )->join( + array('co' => $this->prefix . 'objects'), + 'co.object_id = c.object_id', + array() + ); + + $this->joinedVirtualTables = array('commands' => true); + } + + /** + * Join contacts + */ + protected function joinContacts() + { + $this->select->join( + array('cnc' => $this->prefix . 'contact_notificationcommands'), + 'cnc.command_object_id = co.object_id' + )->join( + array('con' => $this->prefix . 'contacts'), + 'con.contact_id = cnc.contact_id' + ); + } +} \ No newline at end of file diff --git a/modules/monitoring/library/Monitoring/DataView/Command.php b/modules/monitoring/library/Monitoring/DataView/Command.php new file mode 100644 index 000000000..a21c48ee0 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Command.php @@ -0,0 +1,28 @@ + Date: Wed, 27 Aug 2014 16:36:52 +0200 Subject: [PATCH 2/2] Show/Contact: Add notification history to view refs #4804 --- .../application/controllers/ShowController.php | 15 +++++++++++++++ .../application/views/scripts/show/contact.phtml | 3 +++ .../Monitoring/Backend/Ido/Query/ContactQuery.php | 1 + .../Backend/Ido/Query/NotificationQuery.php | 3 ++- .../library/Monitoring/DataView/Contact.php | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index 19c1b7bef..1ad0f29dd 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -123,6 +123,7 @@ class Monitoring_ShowController extends Controller 'contact_alias', 'contact_email', 'contact_pager', + 'contact_object_id', 'contact_notify_service_timeperiod', 'contact_notify_service_recovery', 'contact_notify_service_warning', @@ -149,6 +150,20 @@ class Monitoring_ShowController extends Controller ))->where('contact_id', $contact->contact_id); $this->view->commands = $commands->paginate(); + + $notifications = $this->backend->select()->from('notification', array( + 'host', + 'service', + 'notification_output', + 'notification_contact', + 'notification_start_time', + 'notification_state' + )); + + $notifications->where('contact_object_id', $contact->contact_object_id); + + $this->view->compact = true; + $this->view->notifications = $notifications->paginate(); } $this->view->contact = $contact; diff --git a/modules/monitoring/application/views/scripts/show/contact.phtml b/modules/monitoring/application/views/scripts/show/contact.phtml index fff03a106..45d751fd5 100644 --- a/modules/monitoring/application/views/scripts/show/contact.phtml +++ b/modules/monitoring/application/views/scripts/show/contact.phtml @@ -53,6 +53,9 @@ $contactHelper = $this->getHelper('ContactFlags'); +

translate('Notifications'); ?>:

+ render('list/notifications.phtml') ?> + translate('No such contact'); ?>: diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php index a868d5479..89fa37fcd 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php @@ -13,6 +13,7 @@ class ContactQuery extends IdoQuery 'contact_alias' => 'c.alias COLLATE latin1_general_ci', 'contact_email' => 'c.email_address COLLATE latin1_general_ci', 'contact_pager' => 'c.pager_address', + 'contact_object_id' => 'c.contact_object_id', 'contact_has_host_notfications' => 'c.host_notifications_enabled', 'contact_has_service_notfications' => 'c.service_notifications_enabled', 'contact_can_submit_commands' => 'c.can_submit_commands', diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php index 68a37d83c..882600240 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php @@ -25,7 +25,8 @@ class NotificationQuery extends IdoQuery 'service' => 'o.name2' ), 'contact' => array( - 'notification_contact' => 'c_o.name1' + 'notification_contact' => 'c_o.name1', + 'contact_object_id' => 'c_o.object_id' ), 'command' => array( 'notification_command' => 'cmd_o.name1' diff --git a/modules/monitoring/library/Monitoring/DataView/Contact.php b/modules/monitoring/library/Monitoring/DataView/Contact.php index 7d24d1255..9f78a3b6a 100644 --- a/modules/monitoring/library/Monitoring/DataView/Contact.php +++ b/modules/monitoring/library/Monitoring/DataView/Contact.php @@ -38,6 +38,7 @@ class Contact extends DataView 'contact_notify_host_unreachable', 'contact_notify_host_flapping', 'contact_notify_host_downtime', + 'contact_object_id', 'host_object_id', 'host_name', 'service_object_id',