Skip to content

Instantly share code, notes, and snippets.

@gschueler
Created April 18, 2013 18:49
Show Gist options
  • Save gschueler/5415244 to your computer and use it in GitHub Desktop.
Save gschueler/5415244 to your computer and use it in GitHub Desktop.
import com.dtolabs.rundeck.plugins.notification.NotificationPlugin;
import groovy.text.SimpleTemplateEngine
//define the plugin
rundeckPlugin(NotificationPlugin){
//plugin title shown in GUI
title="Shell Notification"
//plugin description shown in GUI
description="Calls a shell script"
//define configuration options for the plugin
configuration{
scriptPath( title:"Path to script", required:true){
//validation code
new File(it).exists()
}
scriptArgs title:"Arguments"
}
// utility definitions
def engine = new SimpleTemplateEngine()
def generateArgs={text,binding->
engine.createTemplate(text).make(binding).toString()
}
//this common closure will be used for all the notification handlers
def notify= {
//with no args, there is a "config" and an "execution" variable in the context
def command=["/bin/sh","-c"]
if(config.scriptArgs){
command<< config.scriptPath+' '+generateArgs(config.scriptArgs,[execution:execution,trigger:trigger])
}else{
command<< config.scriptPath
}
System.out.println "Got data: ${execution}"
System.err.println("executing command: ${command}")
def proc = command.execute() // Call *execute* on the string
proc.waitForProcessOutput(System.out,System.err)
// print proc.out.text
// System.err.print(proc.err.text)
proc.exitValue()==0
}
//define handlers for the notification events
onsuccess notify
onfailure notify
onstart notify
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment