Esempio n. 1
0
def interpret_ip(monitor_cuid):
    """
    @转换monitorIP
    """
    host_object = get_object(host,cuid=monitor_cuid)
    process_object = get_object(process,cuid=monitor_cuid)
    database_object = get_object(database,cuid=monitor_cuid)
    if host_object:
        return host_object.ipaddr
    if process_object:
        return process_object.related_host_cuid.ipaddr
    if database_object:
        return database_object.related_host_cuid.ipaddr
Esempio n. 2
0
def convert_monitor_object(monitor_cuid):
    """
    @转换monitor对象
    """
    host_object = get_object(host,cuid=monitor_cuid)
    process_object = get_object(process,cuid=monitor_cuid)
    database_object = get_object(database,cuid=monitor_cuid)
    if host_object:
        return '主机-%s'%host_object.ipaddr.encode('utf-8')
    if process_object:
        return '应用-%s'%process_object.label_cn.encode('utf-8')
    if database_object:
        return '数据库-%s'%database_object.label_cn.encode('utf-8')
Esempio n. 3
0
 def process_parse(self):
     '''
     @进程URL和PID监控方法
     '''
     try:
         logger.debug('开始检测进程PID和URL')
         for process_list in self.proccesses:
             processobj = get_object(process,
                                     cuid=process_list.monitor_object)
             value = {}
             if processobj.url_path:
                 url_result = cm_api.check_url(processobj.url_path)
             else:
                 url_result = 0
             pid = get_any_object(
                 current_process,
                 related_process_cuid=process_list.monitor_object)
             if pid:
                 pid_result = 0
             else:
                 pid_result = 1
             value['related_host_cuid'] = processobj.related_host_cuid
             value['pid_result'] = pid_result
             value['url_result'] = url_result
             value['collect_time'] = time.strftime(
                 ISOTIMEFORMAT, time.localtime(time.time()))
             value['process'] = processobj
             self.alarm_object.process_am_parse(value)
         logger.debug('进程PID和URL检测结束,THE END!')
     except Exception, e:
         logger.error(traceback.format_exc())
Esempio n. 4
0
def templatetags(object):
    """
    int 转换为 str
    """
    memory_info = get_object(current_memory,related_host_cuid=object)
    if memory_info:
        return object.cuid
    else:
        return object.cuid
Esempio n. 5
0
    def __init__(self, data):
        '''
        @资源采集对象初始化
        '''

        self.Process_Info = data.get('ProcessPlugin', None)
        self.Disk_Info = data.get('DiskPlugin', None)
        self.Memory_Info = data.get('MemoryPlugin', None)
        self.Cpu_Info = data.get('CpuPlugin', None)
        self.Host_info = data.get('host', None)
        self.collect_time = data.get('collect_time', None)
        self.host = get_object(host, ipaddr=self.Host_info)
        self.alarm_object = Hard_AmObj()
Esempio n. 6
0
 def process_am_parse(self, value):
     '''
     @进程URL和PID告警解析
     '''
     try:
         logger.debug('开始进程告警解析')
         value['monitor_object'] = get_object(
             monitor,
             monitor_object=value['process'].cuid,
             monitor_type='PROCESS')
         value['tag'] = 'PROCESS'
         value['title'] = '进程阈值告警'
         if value['monitor_object'] and self.process_monitor_opt:
             value['alarm_object'] = alarm.objects.filter(
                 related_monitor_cuid=value['monitor_object'].cuid,
                 alarm_tag=value['tag'])
             if value['url_result'] == 1:
                 value['content'] = '进程:%s 产生告警,原因:进程URL:%s拨测失败' % (
                     value['process'].label_cn.encode('utf-8'),
                     value['process'].url_path.encode('utf-8'))
                 if value['alarm_object']:
                     logger.debug('告警已存在,更新告警时间')
                     self.alarm_update(value)
                 else:
                     logger.debug('开始新增告警')
                     self.alarm_insert(value)
             elif value['pid_result'] == 1:
                 value['content'] = '进程:%s 产生告警,原因:进程PID不存在' % (
                     (value['process'].label_cn.encode('utf-8')))
                 if value['alarm_object']:
                     logger.debug('告警已存在,更新告警时间')
                     self.alarm_update(value)
                 else:
                     logger.debug('开始新增告警')
                     self.alarm_insert(value)
             else:
                 if value['alarm_object']:
                     logger.debug('告警已消除,删除活动告警')
                     self.alarm_delete(value)
         else:
             logger.debug(
                 '主机%s不再管理范围,不进行告警解析' %
                 ((value['related_host_cuid'].cuid).encode('utf-8')))
     except Exception, e:
         logger.error(traceback.format_exc())
Esempio n. 7
0
 def ping_parse(self):
     '''
     @PING测主机监控方法
     '''
     try:
         logger.debug('开始PING测所有主机列表')
         for host_list in self.ping_list:
             value = {}
             hostobj = get_object(host, cuid=host_list.monitor_object)
             result = cm_api.check_host(hostobj.ipaddr)
             value['related_host_cuid'] = hostobj
             value['result'] = result
             value['collect_time'] = time.strftime(
                 ISOTIMEFORMAT, time.localtime(time.time()))
             self.alarm_object.ping_am_parse(value)
         logger.debug('主机PING测结束,THE END!')
     except Exception, e:
         logger.error(traceback.format_exc())
Esempio n. 8
0
    def __init__(self):
        '''
        @获取告警监控阈值
        '''

        self.memory_monitor_opt = get_object(monitor_opt,
                                             monitor_type='MEMORY')
        self.disk_monitor_opt = get_object(monitor_opt, monitor_type='DISK')
        self.cpu_monitor_opt = get_object(monitor_opt, monitor_type='CPU')
        self.ping_monitor_opt = get_object(monitor_opt, monitor_type='PING')
        self.process_monitor_opt = get_object(monitor_opt,
                                              monitor_type='PROCESS')
        self.heart_monitor_opt = get_object(monitor_opt, monitor_type='HEART')
Esempio n. 9
0
    def ping_am_parse(self, value):
        '''
        @主机PING测告警解析
        '''

        try:
            logger.debug('开始主机PING测告警解析')
            value['monitor_object'] = get_object(
                monitor,
                monitor_object=value['related_host_cuid'].cuid,
                monitor_type='PING')
            value['tag'] = 'PING'
            value['title'] = 'PING测阈值告警'
            if value['monitor_object'] and self.ping_monitor_opt:
                value['alarm_object'] = alarm.objects.filter(
                    related_monitor_cuid=value['monitor_object'].cuid,
                    alarm_tag=value['tag'])
                if float(value['result']) > float(
                        self.ping_monitor_opt.monitor_alarm_value):
                    value[
                        'content'] = 'PING测主机:%s ,当前丢包率:%s%%,产生告警,原因:ping测丢包率大于%s%%' % (
                            value['related_host_cuid'].ipaddr.encode('utf-8'),
                            float(value['result']),
                            self.ping_monitor_opt.monitor_alarm_value)
                    if value['alarm_object']:
                        logger.debug('告警已存在,更新告警时间')
                        self.alarm_update(value)
                    else:
                        logger.debug('开始新增告警')
                        self.alarm_insert(value)
                else:
                    if value['alarm_object']:
                        logger.debug('告警已消除,删除活动告警')
                        self.alarm_delete(value)
            else:
                logger.debug(
                    '主机%s不再管理范围,不进行告警解析' %
                    ((value['related_host_cuid'].cuid).encode('utf-8')))
        except Exception, e:
            logger.error(traceback.format_exc())
Esempio n. 10
0
 def disk_am_parse(self, value):
     '''
     @硬盘告警解析
     
     '''
     try:
         logger.debug('开始硬盘告警解析')
         value['monitor_object'] = get_object(
             monitor,
             monitor_object=value['related_host_cuid'].cuid,
             monitor_type='DISK')
         value['tag'] = value['device_name']
         value['title'] = '硬盘阈值告警'
         if value['monitor_object'] and self.disk_monitor_opt:
             value['alarm_object'] = alarm.objects.filter(
                 related_monitor_cuid=value['monitor_object'].cuid,
                 alarm_tag=value['tag'])
             if float(value['device_percent']) > float(
                     self.disk_monitor_opt.monitor_alarm_value):
                 value[
                     'content'] = '当前磁盘:%s 磁盘利用率:%s%%,产生告警,原因:磁盘利用率大于%s%%' % (
                         value['device_name'].encode('utf-8'),
                         float(value['device_percent']),
                         float(self.cpu_monitor_opt.monitor_alarm_value))
                 if value['alarm_object']:
                     logger.debug('告警已存在,更新告警时间、告警次数')
                     self.alarm_update(value)
                 else:
                     logger.debug('开始新增告警')
                     self.alarm_insert(value)
             else:
                 if value['alarm_object']:
                     logger.debug('告警已消除,删除活动告警')
                     self.alarm_delete(value)
         else:
             logger.debug(
                 '主机%s不再管理范围,不进行告警解析' %
                 ((value['related_host_cuid'].cuid).encode('utf-8')))
     except Exception, e:
         logger.error(traceback.format_exc())
Esempio n. 11
0
 def memory_am_parse(self, value):
     '''
     @内存告警解析
     
     '''
     try:
         logger.debug('开始内存告警解析')
         value['monitor_object'] = get_object(
             monitor,
             monitor_object=value['related_host_cuid'].cuid,
             monitor_type='MEMORY')
         value['tag'] = 'memory'
         value['title'] = 'MEMORY阈值告警'
         if value['monitor_object'] and self.memory_monitor_opt:
             value['alarm_object'] = alarm.objects.filter(
                 related_monitor_cuid=value['monitor_object'].cuid,
                 alarm_tag=value['tag'])
             if float(value['memory_percent']) > float(
                     self.cpu_monitor_opt.monitor_alarm_value):
                 value['content'] = '内存利用率:%s%%,产生告警,原因:内存利用率大于%s%%' % (
                     float(value['memory_percent']),
                     float(self.memory_monitor_opt.monitor_alarm_value))
                 if value['alarm_object']:
                     logger.error('告警已存在,更新告警时间')
                     self.alarm_update(value)
                 else:
                     logger.error('开始新增告警')
                     self.alarm_insert(value)
             else:
                 if value['alarm_object']:
                     logger.error('告警已消除,删除活动告警')
                     self.alarm_delete(value)
         else:
             logger.debug(
                 '主机%s不再管理范围,不进行告警解析' %
                 ((value['related_host_cuid'].cuid).encode('utf-8')))
     except Exception, e:
         logger.error(traceback.format_exc())
Esempio n. 12
0
 def oracle_mviews_parse(self):
     '''
     @数据库物化视图刷新监控方法
     '''
     logger.debug('开始物化视图刷新状态监测')
     for mview in self.mview_list:
         value = {}
         database_info = get_object(database, cuid=mview.monitor_object)
         value['related_host_cuid'] = database_info.related_host_cuid
         value['database'] = database_info
         value['monitor_object'] = mview
         value['collect_time'] = time.strftime(ISOTIMEFORMAT,
                                               time.localtime(time.time()))
         sql = "select mview_name,last_refresh,last_sync_exception from meta_mview where isactive='Y'"
         result_list = cm_api.exec_sql(database_info.user_name,
                                       database_info.passwd,
                                       database_info.ipaddr,
                                       database_info.port,
                                       database_info.sid, sql)
         for result in result_list:
             value['mview_name'] = result[0]
             value['last_refresh_time'] = result[1]
             value['last_sync_exception'] = result[2]
             self.alarm_object.mview_am_parse(value)