Modifications to accommodate for python 2.6
Change-Id: If959b8a9c7073cbbc97a9712945754116f026c5c
This commit is contained in:
parent
5e20bac393
commit
a8929debda
|
@ -413,8 +413,8 @@ class IO(check.Check):
|
|||
measurements = []
|
||||
timestamp = time.time()
|
||||
for dev_name, stats in filtered_io.iteritems():
|
||||
filtered_stats = {stat: stats[stat]
|
||||
for stat in stats.iterkeys() if stat not in self.stat_blacklist}
|
||||
filtered_stats = dict((stat, stats[stat])
|
||||
for stat in stats.iterkeys() if stat not in self.stat_blacklist)
|
||||
m_list = [metrics.Measurement(key,
|
||||
timestamp,
|
||||
value,
|
||||
|
|
|
@ -66,7 +66,7 @@ class Config(object):
|
|||
'''Read in the config file.'''
|
||||
|
||||
file_config = parser.SafeConfigParser()
|
||||
log.debug("Loading config file from {}".format(self._configFile))
|
||||
log.debug("Loading config file from {0}".format(self._configFile))
|
||||
file_config.readfp(self._skip_leading_wsp(open(self._configFile)))
|
||||
self._config = self._retrieve_sections(file_config)
|
||||
|
||||
|
@ -157,7 +157,7 @@ class Config(object):
|
|||
dimensions = {}
|
||||
try:
|
||||
dim_list = [dim.split(':') for dim in self._config['Main']['dimensions'].split(',')]
|
||||
dimensions.update({key.strip(): value.strip() for key, value in dim_list})
|
||||
dimensions.update(dict((key.strip(), value.strip()) for key, value in dim_list))
|
||||
except ValueError:
|
||||
log.info("Unable to process dimensions.")
|
||||
dimensions = {}
|
||||
|
|
|
@ -468,8 +468,8 @@ def cast_metric_val(val):
|
|||
|
||||
|
||||
def is_valid_hostname(hostname):
|
||||
if hostname.lower() in {'localhost', 'localhost.localdomain',
|
||||
'localhost6.localdomain6', 'ip6-localhost'}:
|
||||
if hostname.lower() in ('localhost', 'localhost.localdomain',
|
||||
'localhost6.localdomain6', 'ip6-localhost'):
|
||||
log.warning("Hostname: %s is local" % hostname)
|
||||
return False
|
||||
if len(hostname) > MAX_HOSTNAME_LEN:
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import logging
|
||||
import re
|
||||
from subprocess import CalledProcessError, check_output
|
||||
from subprocess import CalledProcessError
|
||||
|
||||
from monasca_setup.detection import Plugin, find_process_cmdline, watch_process
|
||||
from monasca_setup.detection.utils import find_addr_listening_on_port
|
||||
from monasca_setup.detection.utils import check_output
|
||||
from monasca_setup import agent_config
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -45,8 +46,8 @@ class Kafka(Plugin):
|
|||
consumers = {}
|
||||
# Find consumers and topics
|
||||
for consumer in self._ls_zookeeper('/consumers'):
|
||||
consumers[consumer] = {topic: kafka.topic_partitions[topic]
|
||||
for topic in self._ls_zookeeper('/consumers/%s/offsets' % consumer)}
|
||||
consumers[consumer] = dict((topic, kafka.topic_partitions[topic])
|
||||
for topic in self._ls_zookeeper('/consumers/%s/offsets' % consumer))
|
||||
|
||||
log.info("\tInstalling kafka_consumer plugin.")
|
||||
self.config['kafka_consumer'] = {'init_config': None,
|
||||
|
|
|
@ -1,9 +1,28 @@
|
|||
""" Util functions to assist in detection.
|
||||
"""
|
||||
import psutil
|
||||
import subprocess
|
||||
|
||||
from monasca_setup import agent_config
|
||||
from subprocess import Popen, PIPE, CalledProcessError
|
||||
|
||||
# check_output was introduced in python 2.7, function added
|
||||
# to accommodate python 2.6
|
||||
try:
|
||||
check_output = subprocess.check_output
|
||||
except AttributeError:
|
||||
def check_output(*popenargs, **kwargs):
|
||||
if 'stdout' in kwargs:
|
||||
raise ValueError('stdout argument not allowed, it will be overridden.')
|
||||
process = Popen(stdout=PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
raise CalledProcessError(retcode, cmd)
|
||||
return output
|
||||
|
||||
def find_process_cmdline(search_string):
|
||||
"""Simple function to search running process for one with cmdline containing.
|
||||
|
|
|
@ -30,6 +30,8 @@ import detection.plugins.swift as swift
|
|||
import detection.plugins.zookeeper as zookeeper
|
||||
import service.sysv as sysv
|
||||
|
||||
from detection.utils import check_output
|
||||
|
||||
# List of all detection plugins to run
|
||||
DETECTION_PLUGINS = [apache.Apache, ceilometer.Ceilometer, cinder.Cinder,
|
||||
glance.Glance, kafka_consumer.Kafka, keystone.Keystone,
|
||||
|
@ -93,12 +95,12 @@ def main(argv=None):
|
|||
for package in ['coreutils', 'sysstat']:
|
||||
#Check for required dependencies for system checks
|
||||
try:
|
||||
output = subprocess.check_output('dpkg -s {}'.format(package),
|
||||
output = check_output('dpkg -s {0}'.format(package),
|
||||
stderr=subprocess.STDOUT,
|
||||
shell=True)
|
||||
except subprocess.CalledProcessError:
|
||||
log.warn("*** {} package is not installed! ***".format(package) +
|
||||
"\nNOTE: If you do not install the {} ".format(package) +
|
||||
log.warn("*** {0} package is not installed! ***".format(package) +
|
||||
"\nNOTE: If you do not install the {0} ".format(package) +
|
||||
"package, you will not receive all of the standard " +
|
||||
"operating system type metrics!")
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue