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://atlas.err:8083/Ticketer/groovlet/show/233
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 “Failure email address” listed */
/* Defining the sendSMS closure */
def sendEmail = {email,body -> final String username = "ticketer@errigal.com"
final String password = "notsame1"
Properties props = new Properties()
props.put("mail.smtp.starttls.enable", "true")
props.put("mail.smtp.auth", "true")
props.put("mail.smtp.host", "smtp.gmail.com")
props.put("mail.smtp.port", "587")
javax.mail.Session session = javax.mail.Session.getInstance(props,
new javax.mail.Authenticator() {
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(username, password)
}
})
try {
javax.mail.Message message = new javax.mail.internet.MimeMessage(session)
message.setFrom(new javax.mail.internet.InternetAddress("peter.phelan@errigal.com"))
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 “Default arg: $defaultArg” log.info “Argument: $arg” log.info “Ticket: $ticket”
def args = arg.split(“,”)
def stateName def successInSendingEmailState def failedToSendEmailStatewhat happens if no fail state provided log.info “Groovlet has received correct amount of arguments. Executing” stateName = args[0].trim(); def emailService = com.errigal.ticketer.utils.DomainUtils.getGrailsService(“emailService”) com.errigal.ticketer.Visibility ticketVisibility = com.errigal.ticketer.Visibility.findByName(ticket.visibility) log.info “Visibility: $ticketVisibility” 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 “Ticket ID: ${ticket.id}”
def emailVo = emailService.getCustomEmailVOWithoutSecurityCheck(ticket.id, entranceEmail) log.info “Email VO: $emailVo”
try{ emailService.sendEmail(emailVo) } catch(Exception e){ log.error “Unable to send email in Groovlet”, e }
Calendar cal = Calendar.getInstance(); creates calendar cal.setTime(new Date()); sets calendar time/date Boolean hasAlarmID = false int currentHour = cal.get(Calendar.HOUR_OF_DAY) def acceptedAlarmIDs = [“LinkPollerInactive”,“TrapForwarderInactive”,“QuartzJobsBlocked”,“NextFireTimeInThePast”,“DefaultEmailUpdatePollJob”,“JBossProcessInactive”,“ApplicationServerProcessInactive”,“OutOfMemoryErrorFound”,
"PermGenErrorFound","mysqlSlaveReplicationFailure","ScriptNotRunning", "TrapParsingInactive",
"mysqlFailure","heartbeatMissing", "TrapCountBreached", "IrisLicenseCheckFailed", "UnableToRunCommand","MobiTrapInactivity","MobiTicketInactivity"]
acceptedAlarmIDs.each{it → if(ticket.summary.contains(it)){hasAlarmID = true}}
if(hasAlarmID){
log.info "Sending Text for ${ticket.id}"
} else {
log.info "Could not find any of ${acceptedAlarmIDs} in '${ticket.summary}' for ${ticket.id}"
}
String body = “”“api_id:3513334 \r user:errigalwaterford \r password:#errigal321!# \r from:Errigal \r to:353833179666,353860623398,353851190587,353863997160,353870574522,353861568567 \r text:$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”“”
if(currentHour >= 16 && currentHour ⇐ 23 && hasAlarmID) { sendEmail(“4157480023@vtext.com”,“$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”) sendEmail(“4155598389@vtext.com”,“$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”) sendEmail(“4157264987@vtext.com”,“$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”) sendEmail(“4157206583@vtext.com”,“$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”) sendEmail(“4158023005@tmomail.net”,“$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”) } else if (currentHour >= 0 && currentHour ⇐ 7 && hasAlarmID) {
// Added Patrick and Dave for now
sendEmail("4157480023@vtext.com","$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary")
sendEmail("sms@messaging.clickatell.com",body)
} else if (hasAlarmID) { sendEmail(“4157480023@vtext.com”,“$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”) sendEmail(“4155598389@vtext.com”,“$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”) sendEmail(“4157264987@vtext.com”,“$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”) sendEmail(“4157206583@vtext.com”,“$ticket.idWithPrefix - $ticket.currentStatus.status : $ticket.summary”) sendEmail(“sms@messaging.clickatell.com”,body) }
This below code is used to change state if the email has been sent (i.e. “Alarm Received” → “Notification Sent”) if (ticket.parent) { log.info “Ticket $ticket.id is no longer a top-level Ticket; cancelling automatic State Change.” } else { Change the Ticket State if it is a top-level Ticket
if (com.errigal.ticketer.GNode.findByWorkflowAndName(ticket.workflow, stateName)) {
log.info "Updating Ticket $ticket.id Status from $ticket.currentStatus.status to $stateName."
ticket.updateStatus(stateName)
def saveResult = ticket.save(failOnError: true)
if (saveResult) {
log.info "State change result: $saveResult"
} else {
def sb = new StringBuilder("Save failed ")
if (hasErrors()) {
sb.append " errors: "
errors.allErrors.each {sb.append it}
} else {
sb.append " no error messages."
}
log.info sb
}
} else {
log.error "$stateName was not found in the $ticket.workflow.name Workflow. Aborting."
}
}