import time import SOAPpy import mws import logs from SOAPpy.Types import faultType, voidType, simplify, booleanType class LogsMWS(mws.mwsAuthentication,mws.mwsGeneral): version = "v1.0" author = "Magnus Agust Skulason, maggias@gmail.com" def getRawLogData(self, resultFilter = ''): try: logsList = [] logsOut = [] logsList = logs.raw_log_data() logsOut = self.__createOutput__(logsList, resultFilter) except Exception, e: raise faultType("SOAP-ENV:Server","getRawLogData failed.",e) return logsOut def getLogData(self, logtype = None, startLog = 0, numOfLogs = 0, mode = '', resultFilter = ''): try: logsList = [] logsOut = [] # Convert apropriate variables to int intStart_log = int(startLog) intNum_of_logs = int(numOfLogs) if logtype == "": logtype = None logsList = self.__getLogsList__(logtype, intStart_log, intNum_of_logs, mode) logsOut = self.__createOutput__(logsList, resultFilter) except Exception, e: raise faultType("SOAP-ENV:Server","getLogData failed.",e) return logsOut def getSMSs(self,startLog,numOfLogs,mode, resultFilter = ''): try: logsList = [] logsOut = [] intStart_log = int(startLog) intNum_of_logs = int(numOfLogs) logsList = self.__getLogsList__('sms', intStart_log, intNum_of_logs, mode) logsOut = self.__createOutput__(logsList, resultFilter) except Exception, e: raise faultType("SOAP-ENV:Server","getSMSs failed.",e) return logsOut def getCalls(self,startLog,numOfLogs,mode, resultFilter = ''): try: logsList = [] logsOut = [] intStart_log = int(startLog) intNum_of_logs = int(numOfLogs) logsList = self.__getLogsList__('call', intStart_log, intNum_of_logs, mode) logsOut = self.__createOutput__(logsList, resultFilter) except Exception, e: raise faultType("SOAP-ENV:Server","getCalls failed.",e) return logsOut def getFaxes(self,startLog,numOfLogs, mode, resultFilter = ''): try: logsList = [] logsOut = [] intStart_log = int(startLog) intNum_of_logs = int(numOfLogs) logsList = self.__getLogsList__('fax', intStart_log, intNum_of_logs, mode) logsOut = self.__createOutput__(logsList, resultFilter) except Exception, e: raise faultType("SOAP-ENV:Server","getFaxes failed.",e) return logsOut def getData(self,startLog,numOfLogs, mode, resultFilter = ''): try: logsList = [] logsOut = [] intStart_log = int(startLog) intNum_of_logs = int(numOfLogs) logsList = self.__getLogsList__('data', intStart_log, intNum_of_logs, mode) logsOut = self.__createOutput__(logsList, resultFilter) except Exception, e: raise faultType("SOAP-ENV:Server","getData failed.",e) return logsOut def getEmails(self,startLog,numOfLogs, mode, resultFilter = ''): try: logsList = [] logsOut = [] intStart_log = int(startLog) intNum_of_logs = int(numOfLogs) logsList = self.__getLogsList__('email', intStart_log, intNum_of_logs, mode) logsOut = self.__createOutput__(logsList, resultFilter) except Exception, e: raise faultType("SOAP-ENV:Server","getEmail failed.",e) return logsOut def getScheduler(self,startLog,numOfLogs, mode, resultFilter = ''): try: logsList = [] logsOut = [] intStart_log = int(startLog) intNum_of_logs = int(numOfLogs) logsList = self.__getLogsList__('scheduler', intStart_log, intNum_of_logs, mode) logsOut = self.__createOutput__(logsList, resultFilter) except Exception, e: raise faultType("SOAP-ENV:Server","getEmail failed.",e) return logsOut def __getLogsList__(self,logtype,intStart_log,intNum_of_logs,mode): logsList = [] if logtype is None: logsList = logs.raw_log_data() else: if intNum_of_logs != 0 and mode != "": logsList = logs.log_data(logtype, intStart_log, intNum_of_logs, mode) elif intNum_of_logs != 0: logsList = logs.log_data(logtype, intStart_log, intNum_of_logs) elif mode != "": logsList = logs.log_data(type = logtype, start_log = intStart_log, mode = mode) else: logsList = logs.log_data(logtype, intStart_log) return logsList def __createOutput__(self,logsList,resultFilter): logsOut = [] for logEntry in logsList: logEntryOut = {} if logEntry["number"] is not None and (resultFilter == "" or resultFilter.find('number') != -1): logEntryOut["number"] = logEntry["number"] if logEntry["name"] is not None and (resultFilter == "" or resultFilter.find('name') != -1): logEntryOut["name"] = logEntry["name"] if logEntry["description"] is not None and (resultFilter == "" or resultFilter.find('description') != -1): logEntryOut["description"] = logEntry["description"] # resulted in a ASCII encoding error! that chars where not in the 128 range # this has to be fixed, unicode encoding should be supported if logEntry["subject"] is not None and (resultFilter == "" or resultFilter.find('subject') != -1): logEntryOut["subject"] = logEntry["subject"].encode('ascii','replace') if logEntry["direction"] is not None and (resultFilter == "" or resultFilter.find('direction') != -1): logEntryOut["direction"] = logEntry["direction"] if logEntry["status"] is not None and (resultFilter == "" or resultFilter.find('status') != -1): logEntryOut["status"] = logEntry["status"] if logEntry["id"] is not None and (resultFilter == "" or resultFilter.find('id') != -1): logEntryOut["id"] = logEntry["id"] if logEntry["contact"] is not None and (resultFilter == "" or resultFilter.find('contact') != -1): logEntryOut["contact"] = logEntry["contact"] if logEntry["duration"] is not None and (resultFilter == "" or resultFilter.find('duration') != -1): logEntryOut["duration"] = logEntry["duration"] if logEntry["duration type"] is not None and (resultFilter == "" or resultFilter.find('duration type') != -1): logEntryOut["durationType"] = logEntry["duration type"] if logEntry["flags"] is not None and (resultFilter == "" or resultFilter.find('flags') != -1): logEntryOut["flags"] = logEntry["flags"] if logEntry["link"] is not None and (resultFilter == "" or resultFilter.find('link') != -1): logEntryOut["link"] = logEntry["link"] if logEntry["time"] is not None and (resultFilter == "" or resultFilter.find('time') != -1): if (self.getReturnSOAP()): logEntryOut["time"] = SOAPpy.dateTimeType(logEntry["time"]) else: logEntryOut["time"] = logEntry["time"] logsOut.append(logEntryOut) return logsOut