Various service detection fixes
* Move monasca-agent and extend user detection from postfix detection plugin to monasca_setup.detection.utils.get_agent_username() * Use get_agent_username() rather than static user name in mon detection plugin * Add logic for determining monasca-notification user from process to mon detection plugin Change-Id: I6a00a8d6574da27274718a71fd813dedd61442b4
This commit is contained in:
parent
9ef72192a2
commit
f2e00f6ebc
@ -1,5 +1,6 @@
|
||||
# Copyright 2016 FUJITSU LIMITED
|
||||
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
|
||||
# Copyright 2017 SUSE Linux GmbH
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@ -185,11 +186,10 @@ class Kibana(detection.Plugin):
|
||||
def _has_metrics_support(self, kibana_url):
|
||||
resp = self._get_metrics_request(kibana_url, method='HEAD')
|
||||
status_code = resp.status_code
|
||||
# although Kibana will respond with 400:Bad Request
|
||||
# Some Kibana versions may respond with 400:Bad Request
|
||||
# it means that URL is available but simply does
|
||||
# not support HEAD request
|
||||
# Looks like guys from Kibana just support GET for this url
|
||||
return status_code == 400
|
||||
return (status_code == 400) or (status_code == 200)
|
||||
|
||||
def _get_metrics_request(self, url, method='GET'):
|
||||
request_url = '%s/%s' % (url, _API_STATUS)
|
||||
|
@ -1,5 +1,6 @@
|
||||
# (c) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
|
||||
# Copyright 2017 Fujitsu LIMITED
|
||||
# Copyright 2017 SUSE Linux GmbH
|
||||
|
||||
import logging
|
||||
import os
|
||||
@ -75,7 +76,7 @@ class Libvirt(plugin.Plugin):
|
||||
has_deps = self.dependencies_installed() if nova_proc else None
|
||||
nova_conf = self._find_nova_conf(nova_proc) if has_deps else None
|
||||
has_cache_dir = self._has_cache_dir() if nova_conf else None
|
||||
agent_user = self._get_agent_username() if has_cache_dir else None
|
||||
agent_user = utils.get_agent_username() if has_cache_dir else None
|
||||
|
||||
self.available = nova_conf and has_cache_dir
|
||||
if not self.available:
|
||||
@ -215,16 +216,6 @@ class Libvirt(plugin.Plugin):
|
||||
def _has_cache_dir():
|
||||
return os.path.isdir(cache_dir)
|
||||
|
||||
@staticmethod
|
||||
def _get_agent_username():
|
||||
agent_user = None
|
||||
try:
|
||||
uid = os.stat('/etc/monasca/agent/agent.yaml').st_uid
|
||||
agent_user = pwd.getpwuid(uid).pw_name
|
||||
except OSError:
|
||||
log.exception('Failed to retrieve agent\'s username')
|
||||
return agent_user
|
||||
|
||||
@staticmethod
|
||||
def _find_nova_conf(nova_process):
|
||||
try:
|
||||
|
@ -1,5 +1,6 @@
|
||||
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
|
||||
# Copyright 2016 FUJITSU LIMITED
|
||||
# Copyright 2017 SUSE Linux GmbH
|
||||
|
||||
"""Classes for monitoring the monitoring server stack.
|
||||
|
||||
@ -17,6 +18,7 @@ import monasca_setup.agent_config
|
||||
import monasca_setup.detection
|
||||
from monasca_setup.detection import find_process_cmdline
|
||||
from monasca_setup.detection import find_process_name
|
||||
from monasca_setup.detection.utils import get_agent_username
|
||||
from monasca_setup.detection.utils import watch_process
|
||||
from monasca_setup.detection.utils import watch_process_by_username
|
||||
|
||||
@ -71,8 +73,8 @@ class MonAgent(monasca_setup.detection.Plugin):
|
||||
def build_config(self):
|
||||
"""Build the config as a Plugins object and return."""
|
||||
log.info("\tEnabling the Monasca Agent process check")
|
||||
return watch_process_by_username('mon-agent', 'monasca-agent', 'monitoring',
|
||||
'monasca-agent')
|
||||
return watch_process_by_username(get_agent_username(), 'monasca-agent',
|
||||
'monitoring', 'monasca-agent')
|
||||
|
||||
def dependencies_installed(self):
|
||||
return True
|
||||
@ -193,8 +195,10 @@ class MonNotification(monasca_setup.detection.Plugin):
|
||||
def build_config(self):
|
||||
"""Build the config as a Plugins object and return."""
|
||||
log.info("\tEnabling the Monasca Notification healthcheck")
|
||||
return watch_process_by_username('mon-notification', 'monasca-notification', 'monitoring',
|
||||
'monasca-notification')
|
||||
notification_process = find_process_cmdline('monasca-notification')
|
||||
notification_user = notification_process.as_dict(['username'])['username']
|
||||
return watch_process_by_username(notification_user, 'monasca-notification',
|
||||
'monitoring', 'monasca-notification')
|
||||
|
||||
def dependencies_installed(self):
|
||||
return True
|
||||
|
@ -1,9 +1,9 @@
|
||||
# (c) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
|
||||
# Copyright 2017 Fujitsu LIMITED
|
||||
# Copyright 2017 SUSE Linux GmbH
|
||||
|
||||
import logging
|
||||
import os
|
||||
import pwd
|
||||
import yaml
|
||||
|
||||
from monasca_setup import agent_config
|
||||
@ -34,7 +34,7 @@ class Postfix(plugin.Plugin):
|
||||
try:
|
||||
has_process = (utils.find_process_cmdline(_POSTFIX_PROC_NAME)
|
||||
is not None)
|
||||
agent_user = self._get_agent_username() if has_process else None
|
||||
agent_user = utils.get_agent_username() if has_process else None
|
||||
has_user = agent_user is not None
|
||||
has_sudoers = (self._has_sudoers(agent_user)
|
||||
if agent_user else False)
|
||||
@ -75,12 +75,6 @@ class Postfix(plugin.Plugin):
|
||||
def dependencies_installed(self):
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _get_agent_username():
|
||||
uid = os.stat('/etc/monasca/agent/agent.yaml').st_uid
|
||||
agent_user = pwd.getpwuid(uid).pw_name
|
||||
return agent_user
|
||||
|
||||
@staticmethod
|
||||
def _has_sudoers(agent_user):
|
||||
test_sudo = os.system(_POSTFIX_CHECK_COMMAND.format(agent_user))
|
||||
|
@ -1,7 +1,11 @@
|
||||
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
|
||||
# Copyright 2017 SUSE Linux GmbH
|
||||
|
||||
""" Util functions to assist in detection.
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import pwd
|
||||
import subprocess
|
||||
from subprocess import CalledProcessError
|
||||
from subprocess import PIPE
|
||||
@ -12,6 +16,11 @@ from oslo_config import cfg
|
||||
from monasca_agent.common.psutil_wrapper import psutil
|
||||
from monasca_setup import agent_config
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
_DEFAULT_AGENT_USER = 'mon-agent'
|
||||
_DETECTED_AGENT_USER = None
|
||||
|
||||
# check_output was introduced in python 2.7, function added
|
||||
# to accommodate python 2.6
|
||||
try:
|
||||
@ -91,6 +100,39 @@ def find_addr_listening_on_port_over_tcp(port):
|
||||
return ip[0].lstrip("::ffff:")
|
||||
|
||||
|
||||
def get_agent_username():
|
||||
"""Determine the user monasca-agent runs as"""
|
||||
|
||||
global _DETECTED_AGENT_USER
|
||||
|
||||
# Use cached agent user in subsequent calls
|
||||
if _DETECTED_AGENT_USER is not None:
|
||||
return _DETECTED_AGENT_USER
|
||||
|
||||
# Try the owner of agent.yaml first
|
||||
try:
|
||||
uid = os.stat('/etc/monasca/agent/agent.yaml').st_uid
|
||||
except OSError:
|
||||
uid = None
|
||||
|
||||
if uid is not None:
|
||||
_DETECTED_AGENT_USER = pwd.getpwuid(uid).pw_name
|
||||
return _DETECTED_AGENT_USER
|
||||
|
||||
# No agent.yaml, so try to find a running monasca-agent process
|
||||
agent_process = find_process_name('monasca-agent')
|
||||
|
||||
if agent_process is not None:
|
||||
_DETECTED_AGENT_USER = agent_process.username()
|
||||
return _DETECTED_AGENT_USER
|
||||
|
||||
# Fall back to static agent user
|
||||
log.warn("Could not determine monasca-agent service user, falling "
|
||||
"back to %s" % _DEFAULT_AGENT_USER)
|
||||
_DETECTED_AGENT_USER = _DEFAULT_AGENT_USER
|
||||
return _DETECTED_AGENT_USER
|
||||
|
||||
|
||||
# NOTE(trebskit) a little poetry never hurt anyone before...right ?
|
||||
def load_oslo_configuration(from_cmd, in_project,
|
||||
for_opts, of_prog=None):
|
||||
|
Loading…
x
Reference in New Issue
Block a user