Skip to content

Instantly share code, notes, and snippets.

@agrohe21
Created March 18, 2014 22:00
Show Gist options
  • Save agrohe21/9630680 to your computer and use it in GitHub Desktop.
Save agrohe21/9630680 to your computer and use it in GitHub Desktop.
CRaSH pba command
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7')
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*
import org.crsh.text.ui.UIBuilder;
import org.crsh.cli.Command;
import org.crsh.cli.Usage;
import org.crsh.cli.Option;
@Usage("Pentaho Business Analytics Server")
class pba {
@Usage("Show the database connection in the BA platform")
@Command
public UIBuilder connections (
@Usage("The username")
@Option(names=["u","username"])
String user,
@Usage("The password")
@Option(names=["p","password"])
String password) {
UIBuilder ui = new UIBuilder();
def http = new RESTClient( 'http://localhost:8080/pentaho/' )
def resp = http.get( path: 'content/ws-run/soapConnectionService/getConnections', query: [userid: 'admin', password: 'password'] )
def data = resp.getData()
ui.table(separator: dashed) {
header(decoration: bold, foreground: black, background: white) {
label("NAME"); label("DB NAME"); label("DB PORT"); label("HOST"); label("DB TYPE"); label("URL")
}
}
data.return.each {
def row = it
ui.row() {
label(row.name, foreground: red, minWidth: 30);
label(row.databaseName);
label(row.databasePort);
label(row.hostname);
label(row.databaseType.name);
label(row.databaseType.extraOptionsHelpUrl);
}
} //end loop connections
return ui
} //end connections
@Usage("Show the Schedules n the BA platform")
@Command
public String schedules (
@Usage("The username")
@Option(names=["u","username"])
String user,
@Usage("The password")
@Option(names=["p","password"])
String password) {
return "Schedules Here ${password}"
}
@Usage("Show the Users in the BA platform")
@Command
public void users (
@Usage("The username")
@Option(names=["u","username"])
String user,
@Usage("The password")
@Option(names=["p","password"])
String password) {
UIBuilder ui = new UIBuilder();
def http = new RESTClient( 'http://localhost:8080/pentaho/' )
// do the first get to pass auth params. The plugin and api cannot use auth params.
http.get( path: 'Home', query: [userid: 'admin', password: 'password'] )
def resp = http.get( path: 'plugin/PentahoStats/api/bis_users_active', query: [userid: 'admin', password: 'password'] )
def data = resp.getData()
def str = resp.data.text
//out << "str: ${str}"
def json = new groovy.json.JsonSlurper().parseText(str)
//out "JSON: ${json}"
out << "\n"
//out "RS: ${json.resultset[0]}"
out << "\n"
//out << "Data: ${data}"
//return json.toString()
/*
ui.table(separator: dashed) {
header(decoration: bold, foreground: black, background: white) {
label("USER NAME"); label("Login Time"); label("DB PORT")
}
}
*/
json.resultset.each {
def row = it
out << "${it[0]}"
out << ":${it[3]}"
out << "\n"
/*
ui.row() {
label(row.name, foreground: red, minWidth: 30);
label(row.databaseName);
label(row.databasePort);
label(row.hostname);
label(row.databaseType.name);
label(row.databaseType.extraOptionsHelpUrl);
}
*/
} //end loop connections
//return ui
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment