<s> import inspect <EOL> import os <EOL> from pprint import pprint <EOL> import sys <EOL> from config import get_checksd_path , get_confd_path <EOL> from util import get_os <EOL> def run_check ( name , path = None ) : <EOL> """<STR_LIT>""" <EOL> confd_path = path or os . path . join ( get_confd_path ( get_os ( ) ) , '<STR_LIT>' % name ) <EOL> try : <EOL> f = open ( confd_path ) <EOL> except IOError : <EOL> raise Exception ( '<STR_LIT>' % confd_path ) <EOL> config_str = f . read ( ) <EOL> f . close ( ) <EOL> check , instances = get_check ( name , config_str ) <EOL> if not instances : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> for instance in instances : <EOL> check . check ( instance ) <EOL> if check . has_events ( ) : <EOL> print "<STR_LIT>" <EOL> pprint ( check . get_events ( ) , indent = <NUM_LIT:4> ) <EOL> print "<STR_LIT>" <EOL> pprint ( check . get_metrics ( ) , indent = <NUM_LIT:4> ) <EOL> def get_check ( name , config_str ) : <EOL> from checks import AgentCheck <EOL> checksd_path = get_checksd_path ( get_os ( ) ) <EOL> if checksd_path not in sys . path : <EOL> sys . path . append ( checksd_path ) <EOL> check_module = __import__ ( name ) <EOL> check_class = None <EOL> classes = inspect . getmembers ( check_module , inspect . isclass ) <EOL> for name , clsmember in classes : <EOL> if AgentCheck in clsmember . __bases__ : <EOL> check_class = clsmember <EOL> break <EOL> if check_class is None : <EOL> raise Exception ( "<STR_LIT>" % name ) <EOL> agentConfig = { <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> return check_class . from_yaml ( yaml_text = config_str , check_name = name , <EOL> agentConfig = agentConfig ) </s>
