2014-02-28 10:19:02 -07:00
|
|
|
import sys
|
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
|
2014-12-17 12:01:44 -07:00
|
|
|
from monasca_agent.collector.checks import AgentCheck
|
2015-06-26 11:53:49 +02:00
|
|
|
from monasca_agent.common.util import Paths
|
2014-05-02 15:06:54 -06:00
|
|
|
|
|
|
|
|
2014-02-28 10:19:02 -07:00
|
|
|
def kill_subprocess(process_obj):
|
|
|
|
try:
|
|
|
|
process_obj.terminate()
|
|
|
|
except AttributeError:
|
2016-03-28 09:56:00 -06:00
|
|
|
os.kill(process_obj.pid, signal.SIGKILL)
|
2014-02-28 10:19:02 -07:00
|
|
|
|
2014-05-06 09:55:15 -06:00
|
|
|
|
2014-02-28 10:19:02 -07:00
|
|
|
def get_check(name, config_str):
|
2015-06-26 11:53:49 +02:00
|
|
|
checksd_path = Paths().get_checksd_path()
|
2014-02-28 10:19:02 -07:00
|
|
|
if checksd_path not in sys.path:
|
|
|
|
sys.path.append(checksd_path)
|
|
|
|
check_module = __import__(name)
|
|
|
|
check_class = None
|
|
|
|
classes = inspect.getmembers(check_module, inspect.isclass)
|
|
|
|
for name, clsmember in classes:
|
|
|
|
if AgentCheck in clsmember.__bases__:
|
|
|
|
check_class = clsmember
|
|
|
|
break
|
|
|
|
if check_class is None:
|
2014-07-01 14:27:12 -07:00
|
|
|
raise Exception(
|
|
|
|
"Unable to import check %s. Missing a class that inherits AgentCheck" % name)
|
2014-02-28 10:19:02 -07:00
|
|
|
|
2014-05-06 09:55:15 -06:00
|
|
|
return check_class.from_yaml(yaml_text=config_str, check_name=name)
|