From 6859746dcb22bb6228c694d7fdc4159667a32e0b Mon Sep 17 00:00:00 2001 From: nook24 Date: Thu, 20 Jul 2017 14:58:25 +0200 Subject: [PATCH] ITC-1380 Refactor SudoServer - Add missing satellite_id to services/browser --- .../NagiosModule/Model/Externalcommand.php | 38 +++++++++++++++---- app/View/Services/browser.ctp | 2 +- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/app/Plugin/NagiosModule/Model/Externalcommand.php b/app/Plugin/NagiosModule/Model/Externalcommand.php index 607fee3b98..b97f6133c1 100644 --- a/app/Plugin/NagiosModule/Model/Externalcommand.php +++ b/app/Plugin/NagiosModule/Model/Externalcommand.php @@ -1150,14 +1150,38 @@ public function test() private function _write($content = '', $satellite_id = 0) { if ($satellite_id > 0) { - //Host or service on SAT system or command for $SAT$_nagios.cmd - $this->Satellite = ClassRegistry::init('DistributeModule.Satellite'); - $sat = $this->Satellite->findById($satellite_id); - if (isset($sat['Satellite']['name'])) { - $file = fopen('/opt/openitc/nagios/var/rw/'.md5($sat['Satellite']['name']).'_nagios.cmd', 'a+'); - fwrite($file, $this->_prefix().$content.PHP_EOL); - fclose($file); + //Loading distributed Monitoring support, if plugin is loaded/installed + $modulePlugins = array_filter(CakePlugin::loaded(), function ($value) { + return strpos($value, 'Module') !== false; + }); + + if (in_array('DistributeModule', $modulePlugins)) { + //DistributeModule is loaded and installed... + //Host or service on SAT system or command for $SAT$_nagios.cmd + $Satellite = ClassRegistry::init('DistributeModule.Satellite'); + + //Host or service on SAT system or command for $SAT$_nagios.cmd + $result = $Satellite->find('first', [ + 'recursive' => -1, + 'conditions' => [ + 'Satellite.id' => $satellite_id + ], + 'fields' => [ + 'Satellite.id', + 'Satellite.name' + ] + ]); + if (isset($result['Satellite']['name'])) { + $file = fopen('/opt/openitc/nagios/var/rw/'.md5($result['Satellite']['name']).'_nagios.cmd', 'a+'); + fwrite($file, $this->_prefix().$content.PHP_EOL); + fclose($file); + } + unset($result); + + }else{ + return false; } + } else { //Host or service from master system or command for master nagios.cmd if ($this->_is_resource()) { diff --git a/app/View/Services/browser.ctp b/app/View/Services/browser.ctp index 7c482062bf..eeeeb99e62 100644 --- a/app/View/Services/browser.ctp +++ b/app/View/Services/browser.ctp @@ -557,7 +557,7 @@ $Servicestatus = new Servicestatus($servicestatus['Servicestatus']);
Form->input('satellite_id', ['type' => 'hidden', 'value' => $service['Host']['satellite_id']]); ?> + echo $this->Form->input('satellite_id', ['type' => 'hidden', 'value' => $service['Host']['satellite_id'], 'id' => 'nag_commandSatelliteId']); ?>