<s> '''<STR_LIT>''' <EOL> import wmi <EOL> from checks import AgentCheck <EOL> class IIS ( AgentCheck ) : <EOL> METRICS = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> SERVICE_CHECK = "<STR_LIT>" <EOL> def __init__ ( self , name , init_config , agentConfig , instances ) : <EOL> AgentCheck . __init__ ( self , name , init_config , agentConfig , instances ) <EOL> self . wmi_conns = { } <EOL> def _get_wmi_conn ( self , host , user , password ) : <EOL> key = "<STR_LIT>" % ( host , user , password ) <EOL> if key not in self . wmi_conns : <EOL> self . wmi_conns [ key ] = wmi . WMI ( host , user = user , password = password ) <EOL> return self . wmi_conns [ key ] <EOL> def check ( self , instance ) : <EOL> host = instance . get ( '<STR_LIT:host>' , None ) <EOL> user = instance . get ( '<STR_LIT:username>' , None ) <EOL> password = instance . get ( '<STR_LIT:password>' , None ) <EOL> instance_tags = instance . get ( '<STR_LIT>' , [ ] ) <EOL> sites = instance . get ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> w = self . _get_wmi_conn ( host , user , password ) <EOL> try : <EOL> wmi_cls = w . Win32_PerfFormattedData_W3SVC_WebService ( ) <EOL> if not wmi_cls : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> except Exception : <EOL> self . log . exception ( '<STR_LIT>' ) <EOL> return <EOL> expected_sites = set ( sites ) <EOL> for iis_site in wmi_cls : <EOL> if iis_site . Name not in sites : <EOL> continue <EOL> if iis_site . Name != '<STR_LIT>' : <EOL> tags = instance_tags + [ '<STR_LIT>' % iis_site . Name ] <EOL> else : <EOL> tags = instance_tags <EOL> status = AgentCheck . CRITICAL if iis_site . ServiceUptime == <NUM_LIT:0> else AgentCheck . OK <EOL> self . service_check ( "<STR_LIT>" , status , tags = [ '<STR_LIT>' % iis_site . Name ] ) <EOL> expected_sites . remove ( iis_site . Name ) <EOL> for metric , mtype , wmi_val in self . METRICS : <EOL> if not hasattr ( iis_site , wmi_val ) : <EOL> if wmi_val == '<STR_LIT>' and hasattr ( iis_site , <EOL> '<STR_LIT>' ) : <EOL> wmi_val = '<STR_LIT>' <EOL> elif wmi_val == '<STR_LIT>' and hasattr ( iis_site , '<STR_LIT>' ) : <EOL> wmi_val = '<STR_LIT>' <EOL> else : <EOL> self . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( metric , wmi_val ) ) <EOL> continue <EOL> value = float ( getattr ( iis_site , wmi_val ) ) <EOL> metric_func = getattr ( self , mtype ) <EOL> metric_func ( metric , value , tags = tags ) <EOL> for remaining_site in expected_sites : <EOL> self . service_check ( "<STR_LIT>" , AgentCheck . CRITICAL , <EOL> tags = [ '<STR_LIT>' % remaining_site ] ) </s>
