def __init__(self): super(Property, self).__init__() self.interface_pc_addr = None self.communication_interface = None self.user_name = "" self.password = "" self.event_file_location = None self.polling_time = 0 self.grace_time = 0 self.fileHandle = None self.fileSize = 0 self.prevFileSize = -1 self.retryCount = 0 self.errorRetryCount = 0 self.local_file_path = None self.downloadStatus = None self.status = PropertyStatus['0:Init'] self.scheduled_execution = None self.scheduler = Scheduler()
def __init__(self): super(Property,self).__init__() self.interface_pc_addr = None self.communication_interface = None self.user_name = "" self.password = "" self.event_file_location = None self.polling_time = 0 self.grace_time = 0 self.fileHandle = None self.fileSize = 0 self.prevFileSize = -1 self.retryCount = 0 self.errorRetryCount = 0 self.local_file_path = None self.downloadStatus = None self.status = PropertyStatus['0:Init'] self.scheduled_execution = None self.scheduler = Scheduler()
class Property(CompositeNode): def __init__(self): super(Property,self).__init__() self.interface_pc_addr = None self.communication_interface = None self.user_name = "" self.password = "" self.event_file_location = None self.polling_time = 0 self.grace_time = 0 self.fileHandle = None self.fileSize = 0 self.prevFileSize = -1 self.retryCount = 0 self.errorRetryCount = 0 self.local_file_path = None self.downloadStatus = None self.status = PropertyStatus['0:Init'] self.scheduled_execution = None self.scheduler = Scheduler() def configure(self,config): super(Property,self).configure(config) set_attribute(self, 'interface_pc_addr', self.interface_pc_addr, config, str) set_attribute(self, 'communication_interface',self.communication_interface, config, str) set_attribute(self, 'user_name',self.user_name, config, str) set_attribute(self, 'password',self.password, config, str) set_attribute(self, 'event_file_location', self.event_file_location, config, str) set_attribute(self, 'polling_time', self.polling_time, config, int) set_attribute(self, 'grace_time', self.grace_time, config, int) if self.parent.debug: msglog.log('Delphi', INFO, "Property interface_pc_addr = %s,communication_interface = %s,user_name = %s, password = %s, \ event_file_location = %s, polling_time = %d, grace_time = %d" %(self.interface_pc_addr, self.communication_interface, self.user_name, \ self.password, self.event_file_location, self.polling_time, self.grace_time)) def configuration(self): config = super(Property,self).configuration() get_attribute(self, 'interface_pc_addr', config) get_attribute(self, 'communication_interface', config) get_attribute(self, 'user_name', config) get_attribute(self, 'password', config) get_attribute(self, 'event_file_location', config) get_attribute(self, 'polling_time', config) get_attribute(self, 'grace_time', config) return config def start(self): msglog.log('Delphi', INFO, "Property Start") if self.parent.enabled: self.local_file_path = '/tmp/'+self.name+'_EVENTS.NSS' # Lets remove if there is any stale file if exists(self.local_file_path): remove(self.local_file_path) if exists(self.local_file_path+'_bak'): remove(self.local_file_path+'_bak') if exists(self.local_file_path+'_prevday'): remove(self.local_file_path+'_prevday') for child in self.children_nodes(): if child.identity == 'status': self.downloadStatus = child break if self.interface_pc_addr == None or self.event_file_location == None: msglog.log('Delphi', WARN, "Check interface pc address and event file location configurations") else: protocol=self.communication_interface+'://' if self.interface_pc_addr[:len(protocol)] == protocol: self.interface_pc_addr = self.interface_pc_addr[len(protocol):] if not self.scheduler.is_started(): try: self.scheduler.start() self.schedulePollAfterInterval( 5 )#start scheduler in 5 second except: msglog.exception() super(Property, self).start() def stop(self): msglog.log('Delphi', INFO, "Property Stop") if self.parent.enabled: try: if self.scheduled_execution: self.scheduled_execution.cancel() if not self.scheduler.is_stopped(): self.scheduler.stop() except: msglog.exception() if exists(self.local_file_path): remove(self.local_file_path) if exists(self.local_file_path+'_bak'): remove(self.local_file_path+'_bak') if exists(self.local_file_path+'_prevday'): remove(self.local_file_path+'_prevday') super(Property, self).stop() def get(self,skipcache=0): return DelphiEnumeratedValue(int(self.status), str(self.status)) def poll(self): if self.parent.debug: msglog.log('Delphi', INFO, "Property Poll") self.fileHandle = None if exists(self.local_file_path+'_bak'): if datetime.now().hour == 0 and datetime.now().minute < self.polling_time: move(self.local_file_path+'_bak', self.local_file_path+'_prevday') if self.parent.debug: msglog.log('Delphi', INFO, self.communication_interface+" connection") if self.communication_interface == 'http': retValue = self.httpDownload() elif self.communication_interface == 'https': retValue = self.httpsDownload() elif self.communication_interface == 'ftp': retValue = self.ftpDownload() else:# communication_interface = 'sftp' retValue = self.sftpDownload() if retValue: try: self.fileHandle = open(self.local_file_path) except IOError, e: msglog.log('Delphi', ERR, "IOError: Unable to open events file. %s" %e) self.status = PropertyStatus['6:File IO Error'] if self.downloadStatus: self.downloadStatus.status = "Download Success at %s" %datetime.now() else:
class Property(CompositeNode): def __init__(self): super(Property, self).__init__() self.interface_pc_addr = None self.communication_interface = None self.user_name = "" self.password = "" self.event_file_location = None self.polling_time = 0 self.grace_time = 0 self.fileHandle = None self.fileSize = 0 self.prevFileSize = -1 self.retryCount = 0 self.errorRetryCount = 0 self.local_file_path = None self.downloadStatus = None self.status = PropertyStatus['0:Init'] self.scheduled_execution = None self.scheduler = Scheduler() def configure(self, config): super(Property, self).configure(config) set_attribute(self, 'interface_pc_addr', self.interface_pc_addr, config, str) set_attribute(self, 'communication_interface', self.communication_interface, config, str) set_attribute(self, 'user_name', self.user_name, config, str) set_attribute(self, 'password', self.password, config, str) set_attribute(self, 'event_file_location', self.event_file_location, config, str) set_attribute(self, 'polling_time', self.polling_time, config, int) set_attribute(self, 'grace_time', self.grace_time, config, int) if self.parent.debug: msglog.log('Delphi', INFO, "Property interface_pc_addr = %s,communication_interface = %s,user_name = %s, password = %s, \ event_file_location = %s, polling_time = %d, grace_time = %d" %(self.interface_pc_addr, self.communication_interface, self.user_name, \ self.password, self.event_file_location, self.polling_time, self.grace_time)) def configuration(self): config = super(Property, self).configuration() get_attribute(self, 'interface_pc_addr', config) get_attribute(self, 'communication_interface', config) get_attribute(self, 'user_name', config) get_attribute(self, 'password', config) get_attribute(self, 'event_file_location', config) get_attribute(self, 'polling_time', config) get_attribute(self, 'grace_time', config) return config def start(self): msglog.log('Delphi', INFO, "Property Start") if self.parent.enabled: self.local_file_path = '/tmp/' + self.name + '_EVENTS.NSS' # Lets remove if there is any stale file if exists(self.local_file_path): remove(self.local_file_path) if exists(self.local_file_path + '_bak'): remove(self.local_file_path + '_bak') if exists(self.local_file_path + '_prevday'): remove(self.local_file_path + '_prevday') for child in self.children_nodes(): if child.identity == 'status': self.downloadStatus = child break if self.interface_pc_addr == None or self.event_file_location == None: msglog.log( 'Delphi', WARN, "Check interface pc address and event file location configurations" ) else: protocol = self.communication_interface + '://' if self.interface_pc_addr[:len(protocol)] == protocol: self.interface_pc_addr = self.interface_pc_addr[ len(protocol):] if not self.scheduler.is_started(): try: self.scheduler.start() self.schedulePollAfterInterval( 5) #start scheduler in 5 second except: msglog.exception() super(Property, self).start() def stop(self): msglog.log('Delphi', INFO, "Property Stop") if self.parent.enabled: try: if self.scheduled_execution: self.scheduled_execution.cancel() if not self.scheduler.is_stopped(): self.scheduler.stop() except: msglog.exception() if exists(self.local_file_path): remove(self.local_file_path) if exists(self.local_file_path + '_bak'): remove(self.local_file_path + '_bak') if exists(self.local_file_path + '_prevday'): remove(self.local_file_path + '_prevday') super(Property, self).stop() def get(self, skipcache=0): return DelphiEnumeratedValue(int(self.status), str(self.status)) def poll(self): if self.parent.debug: msglog.log('Delphi', INFO, "Property Poll") self.fileHandle = None if exists(self.local_file_path + '_bak'): if datetime.now( ).hour == 0 and datetime.now().minute < self.polling_time: move(self.local_file_path + '_bak', self.local_file_path + '_prevday') if self.parent.debug: msglog.log('Delphi', INFO, self.communication_interface + " connection") if self.communication_interface == 'http': retValue = self.httpDownload() elif self.communication_interface == 'https': retValue = self.httpsDownload() elif self.communication_interface == 'ftp': retValue = self.ftpDownload() else: # communication_interface = 'sftp' retValue = self.sftpDownload() if retValue: try: self.fileHandle = open(self.local_file_path) except IOError, e: msglog.log('Delphi', ERR, "IOError: Unable to open events file. %s" % e) self.status = PropertyStatus['6:File IO Error'] if self.downloadStatus: self.downloadStatus.status = "Download Success at %s" % datetime.now( ) else: