def run(self): while not self._stopEvent.isSet(): remainingTime = 30 #self.interval count = 0 while (remainingTime > 0) & (not self._stopEvent.isSet()) : self._stopEvent.wait(self.newCommandPoll) remainingTime -= self.newCommandPoll print str(count) + "Listening for stop" count += 1 print "End of an interval checking for change now" if self.watchedValueHasChanged(): print "Values have changed" subject = "Watch Value Changed for NODE: " + self.watch.curHostName text = self.watch.getCurrentIpString() + "\n" + self.watch.getPreviousValuesStrings() self.watch.updatePropertiesFile() self.watch.getPreviousIP() email = EmailWrapper(self.recipients,subject,text, self.fromAddress, self.password, self.server, self.port) email.mail() if not email.hasErrors: print "Email sent" else: print email.errString else: print "No change to a watched value... Nothing updated\n"
def submit(self): text = 'COMMAND RESULTS:\n' self.preExec = True if self.emailConfig.checkMissingConfig() == True: msg = "Please configure the outgoing email." tkMessageBox.showinfo('Configure Email', msg) self.showPrefs() elif self.emailConfig.getPassword() == "": msg = "Enter your password, hit apply and then resubmit" tkMessageBox.showinfo('Authenticate', msg) self.showPrefs() else: msg = 'Shall I minimize the window and execute ' + os.path.basename(self.pathToExe.get()) + ' now?' if tkMessageBox.askokcancel('Execute Confirmation', msg): self.top.iconify() try: text += self.captureOutput(self.pathToExe.get() + " " + self.args.get()) subject = self.pathToExe.get() + " <-- Command completed" emObj = self.emailConfig email = EmailWrapper(emObj.recipients.get(),subject,text, emObj.fromAddress.get(), emObj.getPassword(),emObj.server.get(),emObj.port.get()) email.mail() if email.hasErrors == True: msg = email.errString msg += "\nValues: \n" msg += email.toString() tkMessageBox.showerror('Mail Error Generated', msg) self.top.deiconify() else: tkMessageBox.showinfo("Execution Complete", subject) self.top.deiconify() except IOError as inst: output = "ERROR GENERATED in EmailAfterExec.submit:\n" output += "Exception Type: " + str(type(inst)) + "\n" output += "Exception: " + str(inst) + "\n" tkMessageBox.showerror('Submit Error Generated', output) self.top.deiconify()
def testConfiguration(self): self.checkCurrentParameters() if self.missingTempParam == True: tkMessageBox.showerror('Missing Configuration Information', 'Please complete all configuration information') else: text = 'This is a test email' subject = 'Email Configuration Test' email = EmailWrapper(self.tmpRecipient,subject,text, self.tmpFromAddress, self.tmpPassword) email.mail() if email.hasErrors: tkMessageBox.showerror('Error Generated', email.errString) else: tkMessageBox.showinfo('Test Completed Successfully', 'You should receive an email with the subject --> ' + subject)