<s> '''<STR_LIT:U+0020>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> from datetime import datetime <EOL> from . model_meta import dashboard_check_cfg , dashboard_check_log <EOL> from . import const <EOL> class JobStateUpdater ( object ) : <EOL> def __init__ ( self , itm_code ) : <EOL> self . logger = logging . getLogger ( __name__ ) <EOL> self . logger . info ( '<STR_LIT>' % itm_code ) <EOL> self . itm_code = itm_code <EOL> self . check_cfg = dashboard_check_cfg . getCfgInDb ( itm_code ) <EOL> self . logger . debug ( '<STR_LIT>' % ( self . check_cfg ) ) <EOL> def isUndefinedCheckItem ( self ) : <EOL> return self . check_cfg is None <EOL> def resultShouldBeNumerical ( self ) : <EOL> return self . check_cfg . check_value_is_number == '<STR_LIT:Y>' <EOL> def updateNumericalResult ( self , check_value , detail_msg , notification_msg = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> status = self . _getStatusByValue ( check_value ) <EOL> self . _updateCheckResult ( check_value , status , detail_msg , notification_msg ) <EOL> def updateNonnumericalResult ( self , status , detail_msg , notification_msg = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> check_value = const . CHECK_VALUE_NA <EOL> self . _updateCheckResult ( check_value , status , detail_msg , notification_msg ) <EOL> def registerCheckingException ( self , exception_msg ) : <EOL> '''<STR_LIT>''' <EOL> notifyJob = JobStateUpdater ( const . CHECK_ITEM_BUILTIN_EXCEPTION_NOTIFY ) <EOL> status = const . CHECK_STATUS_CRITICAL <EOL> detail_msg = "<STR_LIT>" % ( self . itm_code , exception_msg ) <EOL> notifyJob . updateNonnumericalResult ( status , detail_msg ) <EOL> def _getStatusByValue ( self , check_value ) : <EOL> '''<STR_LIT>''' <EOL> self . logger . debug ( "<STR_LIT>" % self . check_cfg . check_value_is_number ) <EOL> try : <EOL> assert ( self . check_cfg . check_value_is_number == '<STR_LIT:Y>' ) <EOL> except Exception as ex : <EOL> self . logger . exception ( "<STR_LIT:%s>" % ex ) <EOL> raise ex <EOL> result = const . CHECK_STATUS_NORMAL <EOL> if self . check_cfg . smaller_is_better : <EOL> if check_value >= self . check_cfg . critical_limit : <EOL> result = const . CHECK_STATUS_CRITICAL <EOL> elif check_value >= self . check_cfg . warning_limit : <EOL> result = const . CHECK_STATUS_WARN <EOL> else : <EOL> if check_value <= self . check_cfg . critical_limit : <EOL> result = const . CHECK_STATUS_CRITICAL <EOL> elif check_value <= self . check_cfg . warning_limit : <EOL> result = const . CHECK_STATUS_WARN <EOL> return result <EOL> def _updateCheckResult ( self , check_value , status , detail_msg , notification_msg = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> if self . check_cfg . enabled_flag != '<STR_LIT:Y>' : <EOL> self . logger . info ( '<STR_LIT>' % ( self . itm_code ) ) <EOL> return <EOL> self . logger . info ( '<STR_LIT>' % check_value ) <EOL> self . logger . info ( '<STR_LIT>' % status ) <EOL> check_timestamp = datetime . now ( ) . strftime ( "<STR_LIT>" ) <EOL> try : <EOL> assert ( status in [ const . CHECK_STATUS_NORMAL , const . CHECK_STATUS_WARN , const . CHECK_STATUS_CRITICAL ] ) <EOL> except Exception as ex : <EOL> self . logger . exception ( ex ) <EOL> raise ex <EOL> self . check_cfg . updateStatus ( check_value , status , check_timestamp , detail_msg , notification_msg ) <EOL> is_critical_event = self . check_cfg . is_critical_event <EOL> if is_critical_event == '<STR_LIT:Y>' : <EOL> self . logger . warn ( "<STR_LIT>" ) <EOL> is_warning_event = self . check_cfg . is_warning_event <EOL> if is_warning_event == '<STR_LIT:Y>' : <EOL> self . logger . warn ( "<STR_LIT>" ) <EOL> is_new_critical_event = self . check_cfg . is_new_critical_event <EOL> if is_new_critical_event == '<STR_LIT:Y>' : <EOL> self . logger . warn ( "<STR_LIT>" ) <EOL> is_new_warning_event = self . check_cfg . is_new_warning_event <EOL> if is_new_warning_event == '<STR_LIT:Y>' : <EOL> self . logger . warn ( "<STR_LIT>" ) <EOL> check_log = dashboard_check_log ( ) <EOL> check_log . initCheckStatus ( self . itm_code , check_timestamp , status , check_value , <EOL> self . check_cfg . warning_limit , self . check_cfg . critical_limit , <EOL> self . check_cfg . shadow_data , detail_msg , notification_msg , <EOL> is_critical_event , is_warning_event , <EOL> is_new_critical_event , is_new_warning_event ) <EOL> check_log . insertLog ( ) </s>
