Hi,
I'm trying to write a script to monitor the audit logs for instances where a user has been created. I can make a REST call to get audit data (rest/auditing/1.0/events?actions=User%20created) but I'd rather use the Java/Groovy API through a Scriptrunner script.
I can't seem to find many working examples of how to do this. Any help would be appreciated.
Thanks
If you want to get logs of the same application instance, it would be much better to utilize direct Java classes, eg. start with AuditingManager from com.atlassian.jira.auditing package.
Yep, just looking for some code samples to help use that package.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
However, if you want to use Groovy, then your code could be something like this
import com.atlassian.jira.component.ComponentAccessor
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
def api_endpoint = "/rest/api/2/mypermissions"
def baseurl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
def authString = "login:password".bytes.encodeBase64().toString()
def remote = new HTTPBuilder(baseurl + api_endpoint)
def query = remote.request(Method.GET, ContentType.JSON) {
headers."Authorization" = "Basic ${authString}"
// Add body = […] if you are planning POST/PUT operations
response.success = { resp, json -> log.warn("Successful = " + json) }
response.failure = { resp, json -> log.warn("Failed = " + json.messages) }
}
Note that here you should expose login and password in plain text, which is insecure, thus using direct Java classes and currently logged in user is preferred.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.