<s> import maas_common <EOL> import subprocess <EOL> class BadOutputError ( maas_common . MaaSException ) : <EOL> pass <EOL> def check_command ( command , startswith , endswith ) : <EOL> output = subprocess . check_output ( command ) <EOL> lines = output . split ( '<STR_LIT:\n>' ) <EOL> matches = False <EOL> for line in lines : <EOL> line = line . strip ( ) <EOL> if line . startswith ( startswith ) : <EOL> matches = True <EOL> if not line . endswith ( endswith ) : <EOL> status = <NUM_LIT:0> <EOL> break <EOL> else : <EOL> if matches : <EOL> status = <NUM_LIT:1> <EOL> else : <EOL> raise BadOutputError ( <EOL> '<STR_LIT>' % output ) <EOL> return status <EOL> def get_hpasmcli_status ( thing ) : <EOL> return check_command ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % thing ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get_drive_status ( ) : <EOL> return check_command ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:all>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get_controller_status ( ) : <EOL> return check_command ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:all>' , '<STR_LIT>' , '<STR_LIT:status>' ) , <EOL> '<STR_LIT>' , '<STR_LIT:OK>' ) <EOL> def get_controller_cache_status ( ) : <EOL> return check_command ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:all>' , '<STR_LIT>' , '<STR_LIT:status>' ) , <EOL> '<STR_LIT>' , '<STR_LIT:OK>' ) <EOL> def get_controller_battery_status ( ) : <EOL> return check_command ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:all>' , '<STR_LIT>' , '<STR_LIT:status>' ) , <EOL> '<STR_LIT>' , '<STR_LIT:OK>' ) <EOL> def main ( ) : <EOL> status = { } <EOL> status [ '<STR_LIT>' ] = get_hpasmcli_status ( '<STR_LIT>' ) <EOL> status [ '<STR_LIT>' ] = get_hpasmcli_status ( '<STR_LIT>' ) <EOL> status [ '<STR_LIT>' ] = get_drive_status ( ) <EOL> status [ '<STR_LIT>' ] = get_controller_status ( ) <EOL> status [ '<STR_LIT>' ] = get_controller_cache_status ( ) <EOL> status [ '<STR_LIT>' ] = get_controller_battery_status ( ) <EOL> maas_common . status_ok ( ) <EOL> for name , value in status . viewitems ( ) : <EOL> maas_common . metric_bool ( name , value ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> with maas_common . print_output ( ) : <EOL> main ( ) </s>
