User Tools
Writing /app/www/public/data/meta/watchdogs/clickatell_texts.meta failed
watchdogs:clickatell_texts
Differences
This shows you the differences between two versions of the page.
| watchdogs:clickatell_texts [2017/08/15 14:34] – created 1carew1 | watchdogs:clickatell_texts [2021/06/25 10:09] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Clickatell - Watchdog Text Messages ====== | ||
| + | Most of the stuff is done by them and theres info of how to on their site | ||
| + | |||
| + | We send an email to clickatell and they send us texts | ||
| + | |||
| + | https:// | ||
| + | |||
| + | SendSMSandEmail | ||
| + | |||
| + | AlarmId to send text is at the end of the - in the watchdog emails | ||
| + | |||
| + | this is set in the resource config of watchdog | ||
| + | |||
| + | Sends message to people depending on what time i.e. guys in america vs ireland | ||
| + | |||
| + | arg, defaultArg, ticket -> | ||
| + | |||
| + | /* | ||
| + | This groovlet is used to send a ticket email using a custom email template (defined in the workflow node | ||
| + | entrance rule)to a group of users who should be notified about a ticket. | ||
| + | |||
| + | If the email sends, the ticket will enter a successInSendingEmailState state and if it fails to send the ticket | ||
| + | will enter a failedToSendEmailState state. These are also defined in the workflow node rule as arguments. | ||
| + | |||
| + | If the groovlet fails to fully execute, any exceptions thrown will be sent to the " | ||
| + | */ | ||
| + | |||
| + | /* | ||
| + | Defining the sendSMS closure | ||
| + | */ | ||
| + | def sendEmail = {email,body -> final String username = " | ||
| + | final String password = " | ||
| + | |||
| + | Properties props = new Properties() | ||
| + | props.put(" | ||
| + | props.put(" | ||
| + | props.put(" | ||
| + | props.put(" | ||
| + | |||
| + | javax.mail.Session session = javax.mail.Session.getInstance(props, | ||
| + | new javax.mail.Authenticator() { | ||
| + | protected javax.mail.PasswordAuthentication getPasswordAuthentication() { | ||
| + | return new javax.mail.PasswordAuthentication(username, | ||
| + | } | ||
| + | }) | ||
| + | |||
| + | try { | ||
| + | |||
| + | javax.mail.Message message = new javax.mail.internet.MimeMessage(session) | ||
| + | message.setFrom(new javax.mail.internet.InternetAddress(" | ||
| + | message.setRecipients(javax.mail.Message.RecipientType.TO, | ||
| + | javax.mail.internet.InternetAddress.parse(email)) | ||
| + | message.setSubject("" | ||
| + | message.setText(body) | ||
| + | |||
| + | javax.mail.Transport.send(message) | ||
| + | |||
| + | } catch (javax.mail.MessagingException e) { | ||
| + | throw new RuntimeException(e) | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | log.info " | ||
| + | log.info " | ||
| + | log.info " | ||
| + | |||
| + | def args = arg.split("," | ||
| + | |||
| + | def stateName | ||
| + | def successInSendingEmailState | ||
| + | def failedToSendEmailState// | ||
| + | |||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | def emailService = com.errigal.ticketer.utils.DomainUtils.getGrailsService(" | ||
| + | |||
| + | com.errigal.ticketer.Visibility ticketVisibility = com.errigal.ticketer.Visibility.findByName(ticket.visibility) | ||
| + | log.info " | ||
| + | |||
| + | com.errigal.ticketer.EmailAccount fromEmailAccount = ticketVisibility.emailAccount | ||
| + | log.info "Email Account: $fromEmailAccount" | ||
| + | |||
| + | //TODO: Support exit email too | ||
| + | def entranceEmail = ticket.workflow.nodes.find{it.name == ticket.currentStatus.status}.entranceEmail | ||
| + | |||
| + | log.info "Email to use: ${entranceEmail}" | ||
| + | log.info " | ||
| + | |||
| + | def emailVo = emailService.getCustomEmailVOWithoutSecurityCheck(ticket.id, | ||
| + | log.info "Email VO: $emailVo" | ||
| + | |||
| + | try{ | ||
| + | | ||
| + | } | ||
| + | catch(Exception e){ | ||
| + | | ||
| + | } | ||
| + | |||
| + | Calendar cal = Calendar.getInstance(); | ||
| + | cal.setTime(new Date()); // sets calendar time/date | ||
| + | Boolean hasAlarmID = false | ||
| + | int currentHour = cal.get(Calendar.HOUR_OF_DAY) | ||
| + | def acceptedAlarmIDs = [" | ||
| + | " | ||
| + | " | ||
| + | acceptedAlarmIDs.each{it -> if(ticket.summary.contains(it)){hasAlarmID = true}} | ||
| + | |||
| + | if(hasAlarmID){ | ||
| + | log.info " | ||
| + | } else { | ||
| + | log.info "Could not find any of ${acceptedAlarmIDs} in ' | ||
| + | } | ||
| + | |||
| + | |||
| + | String body = """ | ||
| + | user: | ||
| + | password:# | ||
| + | from: | ||
| + | to: | ||
| + | text: | ||
| + | |||
| + | if(currentHour >= 16 && currentHour <= 23 && hasAlarmID) | ||
| + | { | ||
| + | sendEmail(" | ||
| + | sendEmail(" | ||
| + | sendEmail(" | ||
| + | sendEmail(" | ||
| + | sendEmail(" | ||
| + | } | ||
| + | else if (currentHour >= 0 && currentHour <= 7 && hasAlarmID) | ||
| + | { | ||
| + | // Added Patrick and Dave for now | ||
| + | sendEmail(" | ||
| + | sendEmail(" | ||
| + | } | ||
| + | else if (hasAlarmID) | ||
| + | { | ||
| + | sendEmail(" | ||
| + | sendEmail(" | ||
| + | sendEmail(" | ||
| + | sendEmail(" | ||
| + | sendEmail(" | ||
| + | } | ||
| + | |||
| + | |||
| + | // This below code is used to change state if the email has been sent (i.e. "Alarm Received" | ||
| + | if (ticket.parent) { | ||
| + | log.info " | ||
| + | } else { | ||
| + | // Change the Ticket State if it is a top-level Ticket | ||
| + | if (com.errigal.ticketer.GNode.findByWorkflowAndName(ticket.workflow, | ||
| + | log.info " | ||
| + | ticket.updateStatus(stateName) | ||
| + | def saveResult = ticket.save(failOnError: | ||
| + | if (saveResult) { | ||
| + | log.info "State change result: | ||
| + | } else { | ||
| + | def sb = new StringBuilder(" | ||
| + | if (hasErrors()) { | ||
| + | sb.append " errors: | ||
| + | errors.allErrors.each {sb.append it} | ||
| + | } else { | ||
| + | sb.append " no error messages." | ||
| + | } | ||
| + | log.info sb | ||
| + | } | ||
| + | } else { | ||
| + | log.error " | ||
| + | } | ||
| + | } | ||
| + | |||