示例#1
0
 exportPath = os.path.normpath('/xcom/alarm' + os.path.sep + fileName)
 
 try:
     if(os.path.isfile(exportPath)):
         log0.warn('The file with name: ' + exportPath + ' already exists, the script will try to delete it.')
         os.remove(exportPath)
     if(not os.path.isdir('/xcom/alarm')):
         log0.warn('Try to create the directory: /xcom/alarm')
         os.makedirs('/xcom/alarm')
     f = open(exportPath, 'w')
     i = 0
     while(i < limit):
         tNow = datetime.datetime.now()
         fStr = tNow.strftime('%Y%m%d%H%M%S')
         tStr = tNow.strftime('%Y-%m-%d %H:%M:%S')
         u, h = CommonFunc.getHexFromStr(tStr)
         h = ':'.join(h[o:o+2] for o in range(0, len(h), 2))
         j = 0
         while(j < 1000):
             for p in range(0, 5):
                 li[p] = fStr + str(counter) + '|.1.3.6.1.4.1.193.176.50.2.5|' + str(p + 1) + '|' + h + '|Failed to establish X2 connection|3|licId01|Cannot connect to X2 remote address. remote ip [192.168.20.10] port [7790]. errno [67] error description [Address already in use]\n'
                 i += 1
                 j += 1
                 counter += 1
                 if(counter > 4294967296):
                     counter = 1            
             f.writelines(li)
         log0.info("Write 1000 record, total number: " + str(i))
         f.flush()
     f.close()
 except Exception as e:
示例#2
0
    #try to kill the process if exists
    try:
        p.kill()
    except Exception as e:
        msg = 'The "PS" process has already been killed, please ignore this log.'

    for line in sLi:
        if(line.find(moduleName) > -1 and line.find('grep ' + name) == -1):
            return int(line.split()[1])
    return -1

if __name__ == '__main__':
    #print os.path.split(sys.argv[0])[1].split('.')[0]
    #print os.getpid()
    print datetime.now().second
    h,x = CommonFunc.getHexNow()
    print x
    
    '''print getPidByName('54352')
    i = 0
    while True:
        time.sleep(1)
        i += 1
        print i
        if(i > 10):
            sys.exit(1)'''
    
    #getPidByName('pmFileGen1020.py -t OCGAS')
    #i, h = CommonFunc.getHexNow()
    #print os.listdir('/xcom/alarm')
    #print type(time.localtime(os.path.getmtime('/xcom/alarm/' + os.listdir('/xcom/alarm')[0])))
示例#3
0
 log0.info('Time is correct, we may try to send a trap.')
 #log0.critical('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' + str(liAlarm5Min[i]) + '&&&&&&&&&&&&&&&' + str(i))
 #Below part will try to send the alarm trap
 id += 1
 alarmSplit = liAlarm5Min[i].strip().split('|')
 if(len(alarmSplit) > 8):
     alarmid = None
     #This means this alarm is the has peer alarm
     if(peerAlarm.has_key(alarmSplit[8].strip())):
         #change the alarmid to the it's peer's
         id -= 1
         alarmid = peerAlarm.get(alarmSplit[8].strip())
     else:
         alarmid = datetime.now().strftime('%Y%m%d%H%M%S') + str(id)
         peerAlarm[alarmSplit[8].strip()] = alarmid
     x, h = CommonFunc.getHexNow()
     alarmSplit[3] = ':'.join(h[i:i+2] for i in range(0, len(h), 2))
     liAlarm5Min[i] = alarmid + '|' + '|'.join(alarmSplit[1:8])
     if(sendTrapThisRound):
         log0.warn('Send a trap now.')
         sendSingleTrap(snmpEng, snmpCfg, liAlarm5Min[i])
     else:
         log0.warn('Time is right, but will not send trap since the flag show we cannot send trap this round.')
     #sendSingleTrap('Send a trap: ' + liAlarm5Min[i])
 else:
     x, h = CommonFunc.getHexNow()
     alarmSplit[3] = ':'.join(h[i:i+2] for i in range(0, len(h), 2))
     liAlarm5Min[i] = datetime.now().strftime('%Y%m%d%H%M%S') + str(id) + '|' + '|'.join(alarmSplit[1:8])
     if(sendTrapThisRound):
         sendSingleTrap(snmpEng, snmpCfg, liAlarm5Min[i])
     #sendSingleTrap('Send a trap: ' + liAlarm5Min[i])