You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2014/06/26 01:12:20 UTC
git commit: AMBARI-5888. Nagios Alerts On SLES Toggle In Maintenance
Mode (Jonathan Hurley via smohanty)
Repository: ambari
Updated Branches:
refs/heads/branch-1.6.1 4dc042e9d -> bf3a59e84
AMBARI-5888. Nagios Alerts On SLES Toggle In Maintenance Mode (Jonathan Hurley via smohanty)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bf3a59e8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bf3a59e8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bf3a59e8
Branch: refs/heads/branch-1.6.1
Commit: bf3a59e84b079c3088e69a61fc3e30194f113fc2
Parents: 4dc042e
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Wed Jun 25 16:11:58 2014 -0700
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Wed Jun 25 16:11:58 2014 -0700
----------------------------------------------------------------------
.../NAGIOS/package/scripts/nagios_service.py | 45 +++++++++++++++++---
.../NAGIOS/package/scripts/nagios_service.py | 42 ++++++++++++++++--
.../stacks/1.3.2/NAGIOS/test_nagios_server.py | 17 +++++---
.../stacks/2.0.6/NAGIOS/test_nagios_server.py | 20 ++++++---
.../src/addOns/nagios/scripts/nagios_alerts.php | 19 +++++----
5 files changed, 110 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/bf3a59e8/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_service.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_service.py b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_service.py
index cc411b5..1bcb14e 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_service.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/NAGIOS/package/scripts/nagios_service.py
@@ -20,17 +20,50 @@ Ambari Agent
"""
+import os
+import signal
+
from resource_management import *
+from os.path import isfile
+
def nagios_service(action='start'): # start or stop
import params
+
+ nagios_pid_file = format("{nagios_pid_file}")
- if action == 'start':
- command = "service nagios start"
+ command_path = "/usr/local/bin/:/bin/:/sbin/"
+
+ if action == 'start':
+ Execute("service nagios start", path = command_path )
elif action == 'stop':
- command = format("service nagios stop && rm -f {nagios_pid_file}")
+ # attempt to grab the pid in case we need it later
+ nagios_pid = 0
+ if isfile(nagios_pid_file):
+ with open(nagios_pid_file, "r") as file:
+ try:
+ nagios_pid = int(file.read())
+ Logger.info("Nagios is running with a PID of {0}".format(nagios_pid))
+ except:
+ Logger.info("Unable to read PID file {0}".format(nagios_pid_file))
+ finally:
+ file.close()
+
+ Execute("service nagios stop", path = command_path)
+
+ # on SUSE, there is a bug where Nagios doesn't kill the process
+ # but this could also affect any OS, so don't restrict this to SUSE
+ if nagios_pid > 0:
+ try:
+ os.kill(nagios_pid, 0)
+ except:
+ Logger.info("The Nagios process has successfully terminated")
+ else:
+ Logger.info("The Nagios process with ID {0} failed to terminate; explicitly killing.".format(nagios_pid))
+ os.kill(nagios_pid, signal.SIGKILL)
- Execute( command,
- path = "/usr/local/bin/:/bin/:/sbin/"
- )
+ # in the event that the Nagios scripts don't remove the pid file
+ if isfile( nagios_pid_file ):
+ Execute(format("rm -f {nagios_pid_file}"))
+
MonitorWebserver("restart")
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/bf3a59e8/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_service.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_service.py b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_service.py
index f98344c..8f47702 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_service.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_service.py
@@ -20,16 +20,50 @@ Ambari Agent
"""
+import os
+import signal
+
from resource_management import *
+from os.path import isfile
+
def nagios_service(action='start'): # start or stop
import params
+
+ nagios_pid_file = format("{nagios_pid_file}")
if action == 'start':
- command = format("service {nagios_service_name} start")
+ command = format("service {nagios_service_name} start")
+ Execute(command)
elif action == 'stop':
- command = format("service {nagios_service_name} stop && rm -f {nagios_pid_file}")
+ # attempt to grab the pid in case we need it later
+ nagios_pid = 0
+ if isfile(nagios_pid_file):
+ with open(nagios_pid_file, "r") as file:
+ try:
+ nagios_pid = int(file.read())
+ Logger.info("Nagios is running with a PID of {0}".format(nagios_pid))
+ except:
+ Logger.info("Unable to read PID file {0}".format(nagios_pid_file))
+ finally:
+ file.close()
+
+ command = format("service {nagios_service_name} stop")
+ Execute(command)
+
+ # on SUSE, there is a bug where Nagios doesn't kill the process
+ # but this could also affect any OS, so don't restrict this to SUSE
+ if nagios_pid > 0:
+ try:
+ os.kill(nagios_pid, 0)
+ except:
+ Logger.info("The Nagios process has successfully terminated")
+ else:
+ Logger.info("The Nagios process with ID {0} failed to terminate; explicitly killing.".format(nagios_pid))
+ os.kill(nagios_pid, signal.SIGKILL)
- Execute( command,
- )
+ # in the event that the Nagios scripts don't remove the pid file
+ if isfile( nagios_pid_file ):
+ Execute(format("rm -f {nagios_pid_file}"))
+
MonitorWebserver("restart")
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/bf3a59e8/ambari-server/src/test/python/stacks/1.3.2/NAGIOS/test_nagios_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.2/NAGIOS/test_nagios_server.py b/ambari-server/src/test/python/stacks/1.3.2/NAGIOS/test_nagios_server.py
index a71e74f..b57b68f 100644
--- a/ambari-server/src/test/python/stacks/1.3.2/NAGIOS/test_nagios_server.py
+++ b/ambari-server/src/test/python/stacks/1.3.2/NAGIOS/test_nagios_server.py
@@ -49,19 +49,22 @@ class TestNagiosServer(RMFTestCase):
self.assertNoMoreResources()
- def test_stop_default(self):
+ @patch('os.path.isfile')
+ def test_stop_default(self, os_path_isfile_mock):
+ src_dir = RMFTestCase._getSrcFolder()
+ os_path_isfile_mock.side_effect = [False, True]
+
self.executeScript(
"1.3.2/services/NAGIOS/package/scripts/nagios_service.py",
classname="NagiosServer",
command="stop",
config_file="default.json"
)
- self.assertResourceCalled('Execute',
- 'service nagios stop && rm -f /var/run/nagios/nagios.pid',
- path=['/usr/local/bin/:/bin/:/sbin/']
- )
- self.assertResourceCalled('MonitorWebserver', 'restart',
- )
+
+ self.assertResourceCalled('Execute','service nagios stop', path=['/usr/local/bin/:/bin/:/sbin/'])
+ self.assertResourceCalled('Execute','rm -f /var/run/nagios/nagios.pid')
+ self.assertResourceCalled('MonitorWebserver', 'restart')
+
self.assertNoMoreResources()
http://git-wip-us.apache.org/repos/asf/ambari/blob/bf3a59e8/ambari-server/src/test/python/stacks/2.0.6/NAGIOS/test_nagios_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/NAGIOS/test_nagios_server.py b/ambari-server/src/test/python/stacks/2.0.6/NAGIOS/test_nagios_server.py
index 1e9b5f3..ae5eaf4 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/NAGIOS/test_nagios_server.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/NAGIOS/test_nagios_server.py
@@ -18,7 +18,9 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
-from mock.mock import MagicMock, patch
+import os
+
+from mock.mock import Mock, MagicMock, patch
from stacks.utils.RMFTestCase import *
@@ -47,18 +49,22 @@ class TestNagiosServer(RMFTestCase):
self.assertNoMoreResources()
- def test_stop_default(self):
+ @patch('os.path.isfile')
+ def test_stop_default(self, os_path_isfile_mock):
+ src_dir = RMFTestCase._getSrcFolder()
+ os_path_isfile_mock.side_effect = [False, True]
+
self.executeScript(
"2.0.6/services/NAGIOS/package/scripts/nagios_service.py",
classname="NagiosServer",
command="stop",
config_file="default.json"
)
- self.assertResourceCalled('Execute',
- 'service nagios stop && rm -f /var/run/nagios/nagios.pid'
- )
- self.assertResourceCalled('MonitorWebserver', 'restart',
- )
+
+ self.assertResourceCalled('Execute','service nagios stop')
+ self.assertResourceCalled('Execute','rm -f /var/run/nagios/nagios.pid')
+ self.assertResourceCalled('MonitorWebserver', 'restart')
+
self.assertNoMoreResources()
http://git-wip-us.apache.org/repos/asf/ambari/blob/bf3a59e8/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
----------------------------------------------------------------------
diff --git a/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php b/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
index e0fd69e..d15b023 100644
--- a/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
+++ b/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
@@ -100,13 +100,12 @@ function hdp_mon_generate_response( $response_data )
define ("WEBHCAT_SERVICE_CHECK", "WEBHCAT::WebHCat Server status check");
define ("PUPPET_SERVICE_CHECK", "PUPPET::Puppet agent down");
- /* If SUSE, status file is under /var/lib/nagios */
- if (file_exists("/etc/SuSE-release")) {
- $status_file="/var/nagios/status.dat";
- } else {
- $status_file="/var/nagios/status.dat";
+ // on SUSE, some versions of Nagios stored data in /var/lib
+ $status_file = "/var/nagios/status.dat";
+ if (!file_exists($status_file) && file_exists("/etc/SuSE-release")) {
+ $status_file = "/var/lib/nagios/status.dat";
}
-
+
$q1="";
if (array_key_exists('q1', $_GET)) {
$q1=$_GET["q1"];
@@ -296,11 +295,10 @@ function hdp_mon_generate_response( $response_data )
#echo $matches[1][0] . ", " . $matches[1][1] . "\n";
$services_objects = array ();
$i = 0;
- foreach ($matches[1] as $object) {
+ foreach ($matches[1] as $object) {
$servicestatus = getParameterMap($object, $servicestatus_attributes);
switch ($alert_type) {
case "all":
-
if (empty($host) || $servicestatus['host_name'] == $host) {
$servicestatus['service_type'] = get_service_type($servicestatus['service_description']);
$srv_desc = explode ("::",$servicestatus['service_description'],2);
@@ -353,12 +351,14 @@ function hdp_mon_generate_response( $response_data )
}
break;
}
+
if (!empty($servicestatus)) {
$services_objects[$i] = $servicestatus;
$i++;
}
}
- /* echo "COUNT : " . count ($services_objects) . "\n"; */
+
+ // echo "COUNT : " . count ($services_objects) . "\n";
return $services_objects;
}
@@ -459,6 +459,7 @@ function hdp_mon_generate_response( $response_data )
return $map;
}
+
function indent($json) {
$result = '';