Ejemplo n.º 1
0
alarm_id_file = os.path.normpath(snmp_conf + sep + 'oids' + sep + 'alarmid_oids')
timestamp_file = os.path.normpath(snmp_conf + sep + 'oids' + sep + 'time_oids')
v3_auth_file = os.path.normpath(snmp_conf + sep + 'v3_auth')
id_file = os.path.normpath(snmp_conf + sep + 'id')

option_cfg = os.path.normpath(dir_cur + sep + 'config' + sep + 'snmp_sync' + sep + 'manual_options.cfg')

options = Options(option_cfg)

traps_map = SnmpTrapUtils.read_used_trap_templates(options, template_dir, mapping_file, alarm_id_file, timestamp_file)

if not traps_map:
    msg = 'Fail to read the alarm template files.'
    logging.error(msg)
    # print msg
else:
    list_engine = SnmpTrapUtils.init_trap_engine(traps_map, options, v3_auth_file)
    t = SnmpTrapUtils.SyncTrap(options, traps_map, list_engine[0], list_engine[1], list_engine[2],
                               list_engine[3], id_file)
    try:
        t.start()
        while not t.b_stop:
            time.sleep(.5)
    except KeyboardInterrupt:
        t.stop()
        msg = "Somebody try to kill me by 'CTRL + C', I am going to exit now."
        logging.info(msg)
        print msg


Ejemplo n.º 2
0
    engine_id = None if '' == options.engineid else options.engineid
    active_num = 20
    firstround=True
    p_id = Properties(id_file)
    id = int(p_id.get_property('id')) + 1
    
    try:
    
        old_alarm_ids = readOldAlarmIds(alarm_id_file)
        traps_map = SnmpTrapUtils.read_used_trap_templates(options, template_dir, mapping_file, alarm_oid_file, timestamp_file)

        if not traps_map:
            msg = 'Fail to read the alarm template files.'
            log0.error(msg)    
        else:
            list_engine = SnmpTrapUtils.init_trap_engine(traps_map,options,v3_auth_file,client_ip,engine_id)
        
        if len(old_alarm_ids)!=0:
            log0.info("start alarm sync")
            sendClearAlarms(old_alarm_ids,active_num,traps_map,list_engine)
            id,old_alarm_ids=sendActiveAlarms(active_num,traps_map,list_engine,id)
            writeAlarmIdBack(alarm_id_file, old_alarm_ids)
            log0.info("end to sync alarms")
        else:
            log0.info("start to sync alarms")
            id,old_alarm_ids=sendActiveAlarms(active_num, traps_map,list_engine,id,True)
            log0.info("alarm sync finished")
            writeAlarmIdBack(alarm_id_file, old_alarm_ids)
        
        writeCountBack(id,id_file)