예제 #1
0
    def __init__(self, name, config_dict):
        '''
        Constructor
        '''
        if config_dict is None:
            raise ConfigurationError, 'SMTP Listener must have a configuration stanza'
        
        # Set debug level
        if 'debug_level' in config_dict:
            if config_dict['debug_level'] == 'true':
                self.debug_level = True
            else:
                self.debug_level = False
        else:
            self.debug_level = False
                
        # From: single user name
        if 'from' in config_dict:
            self.sender = config_dict['from']
        else:
            get_logger().error('SMTP sender not configured')
            raise ConfigurationError, 'SMTP sender not configured'
            
        # To: is a list of people to notify    
        if 'to' in config_dict:
            self.receivers = config_dict['to']
        else:
            get_logger().error('SMTP receivers not configured')
            raise ConfigurationError, 'SMTP receivers not configured'
        
        # Server is host:port
        if 'server' in config_dict:
            self.server = config_dict['server']
        else:
            get_logger().error('SMTP server not configured')
            raise ConfigurationError, 'SMTP server not configured'
        
        # If server login required
        if 'login' in config_dict:
            (self.uid,self.password) = config_dict['login'].split(':')
        else:
            self.uid = None
            self.password = None

        # User defined templates for subject and message body                        
        if 'subj_template' in config_dict:
            self.subj_template = Template(config_dict['subj_template'])
        else:
            self.subj_template = Template('${0} - ${1}:${2}'.format(ALERT_ATTR_ALERT_ID,
                                                                    ALERT_ATTR_EVENT_LOC_TYPE,
                                                                    ALERT_ATTR_EVENT_LOC))

        if 'body_template' in config_dict:
            self.body_template = Template(config_dict['body_template'].decode('string-escape'))
        else:
            self.body_template = Template('${0}\r\n\r\n${1}\r\n\r\n'.format(ALERT_ATTR_REASON,
                                                                        ALERT_ATTR_RECOMMENDATION))
        
        AlertListener.__init__(self,name,config_dict)
예제 #2
0
 def __init__(self, name, config_dict):
     '''
     Constructor
     '''
     if config_dict is not None and 'prefix' in config_dict:
         self.prefix = config_dict['prefix']
     else:
         self.prefix = ''
     get_logger().debug('Creating PrintAlertListner with prefix {0}'.format(self.prefix))
     AlertListener.__init__(self, name, config_dict)
     return
예제 #3
0
    def __init__(self, name, config_dict=None):
        """
        Constructor
        """
        if config_dict is None or "program" not in config_dict:
            raise ValueError, "{0}: must configure a program to call".format(name)

        self.program = config_dict["program"]
        if not os.path.isabs(self.program):
            raise ValueError, "{0} must be specified with an absolute path".format(self.program)

        AlertListener.__init__(self, name, config_dict)
예제 #4
0
    def __init__(self, name, config_dict):
        '''
        Constructor
        '''
        AlertListener.__init__(self,name,config_dict)
        
        if config_dict is not None and 'format' in config_dict:
            self.formatter = config_dict['format']
            if self.formatter in ['json','csv','text','brief']:
                pass
            else:
                get_logger().warn('Invalid formatter specified: \'{0}\'. Defaulting to \'csv\''.format(self.formatter))
                self.formatter = "csv"
        else:
            self.formatter = "csv"
            
        if config_dict is not None and 'file' in config_dict:
            self.file_name = config_dict['file']
        else:
            log_dir = get_service(TEAL_LOG_DIR)
            self.file_name = os.path.join(log_dir,'tealalert.log')

        if config_dict is not None and 'mode' in config_dict:
            cfg_mode = config_dict['mode']
            if cfg_mode == 'append':
                mode = "a"
            elif cfg_mode == 'write':
                mode = 'w'
            else:        
                get_logger().warn('Invalid mode specified: \'{0}\'. Defaulting to \'append\''.format(cfg_mode))
                mode = 'a'                
        else:
            mode = 'a'
            
        try:
            if self.file_name == 'stderr':
                self.file = sys.stderr
            elif self.file_name == 'stdout':
                self.file = sys.stdout
            else:
                self.file = open(self.file_name, mode)
                
            if self.formatter == 'csv':
                self.writer = csv.DictWriter(self.file, ALERT_COLS_SELECT, extrasaction='ignore')
                get_logger().info("CSV Headings: {0}".format(ALERT_COLS_SELECT))
        except IOError,e:
            get_logger().error('Could not open {0}: {1}'.format(self.file_name, e))
            self.file = None    
예제 #5
0
    def __init__(self, name, config_dict=None):
        '''	Constructor '''
        AlertListener.__init__(self, name, config_dict)

        # Check if environment variable is set to allow testing when an HMC isn't present
        self.log_only = (os.environ.get(CNM_TEST_LISTENER_LOG_ONLY, 'N') != 'N')

        # Try to get the retry count from configuration
        if config_dict is None or SFP_RETRY_COUNT not in config_dict:
            self.sfp_retry_count = 5
        else:
            self.sfp_retry_count = config_dict[SFP_RETRY_COUNT]
            
        # Get addresses for HMCs
        db = registry.get_service(SERVICE_DB_INTERFACE)
        connection = db.get_connection()
        cursor = connection.cursor()
        self.hmc_primary_addr = self._get_hmc_address(db, cursor, 'ea_primary_hmc')
        self.hmc_backup_addr = self._get_hmc_address(db, cursor, 'ea_backup_hmc')
        connection.close()
        self.hmc_connected = False
        
        # Setup client name 
        self.client_name = socket.gethostname() + ":cnm_alert_listener"
        
        # Get initial connection
        self.hmc_using_addr = self.hmc_primary_addr    # Which HMC were using to know where to start retries

        self.queue = Queue.Queue()
        
        self.condition = threading.Condition()

        self.running = True # Set here so we don't run into timing issues in shutdown
        self.process_thread = threading.Thread(group=None,target=self.start,name='alert_processor')
        self.process_thread.setDaemon(True)
        self.process_thread.start()
	
        return 
예제 #6
0
 def __init__(self, name, config_dict=None):
     '''
     Constructor
     '''
     self.sensor = 'TealSendAlert'
     AlertListener.__init__(self, name, config_dict)