Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for groovy code examples for searching the audit logs

Tom Hudgins
Contributor
October 28, 2020

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

1 answer

1 vote
Yevgen Lasman
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2020

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.

Tom Hudgins
Contributor
October 28, 2020

Yep, just looking for some code samples to help use that package. 

Thanks

Yevgen Lasman
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2020

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.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.12
TAGS
AUG Leaders

Atlassian Community Events