Has anyone ever written a script that touches an external (to Jira) webpage every hour or so, and performs some action in Jira based on the response code?
I manage a bunch of web apps, and would love to get Jira issues sent to me when a site responds with something other than a 200? Create a new issue in a project with details on the site that failed the status check.
Ideally, I would have a bunch of parent issues for the sites, and if there is a problem with a site, a subtask is created under the site’s parent issue. That way, I could add more sites to the checker over time, and let the script loop through all of the main issues.
We are running Jira Server v9.7, and the latest Scriptrunner & Automation plugins.
Anyone have experience touching external sites with scriptrunner? Even though I’m not fluent with groovy, I could probably piece together the rest of the script myself using previous community posts and the Adaptivist Library (and ChatGPT…LOL).
Thanks all!
Hello @Timothy Ryner
Is Jira the right place to be monitoring health of another system though?
If you have scriptrunner then you can create a Job that is scheduled.
There are a number of ways to do this but I guess as this is in groovy lets use this.
Have a look at groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import groovyx.net.http.HttpResponseDecorator
log.info("Checking if the system is running.")
def host = 'https://host.domain.com'
def http = new HTTPBuilder(host)
http.request(Method.GET) { req ->
uri.path = '/rest/api/latest/myself'
headers.'APIKEY' = 'i-need-a-key'
response.success = { HttpResponseDecorator resp, data ->
log.info "System running: ${resp.statusLine}"
}
response.failure = { HttpResponseDecorator resp ->
// create an issue in Jira
createIssue(
}
}
def createIssue(String code, String system...) {
}
HTTP utilities aside, I would focus on the point Graham mentioned - you don't want to turn Jira into a monitoring tool, because it isn't suited for it and it's just a "tool" between monitoring and the target site. Whatever it is you're about to do, there are better apps to do it, rather than creating some inline scripts you have virtually zero control of. What if the jobs stop working? How will you solve logging? What if Jira isn't working, is the monitoring in turn also not working? What if the automation user gets inactivated / loses permissions? This is prone to a lot of chained issues that you would be trying to solve over a long period of time and it still will have a room for error. Jira is not the right tool to do monitoring from, and by using it so you will eventually, most likely, hit some of the guardrails and degrade performance of the instance.
I had my experience with people trying to make their projects work as databases, monitorings, log collectors, and it was always ugly and resulted in them going away using proper tools for the job, rather than pulling the entire instance down because of their rather dull automation (which they found to be failing on several occasions). Guardrails are real, and they do bite if you use Jira for something it wasn't meant to do.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Graham for the start! I'll fiddle with this over the coming weeks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Graham,
I'm working through the script, and it's going relatively well. A great little project to start learning groovy!
The reponse.success and response.failure handlers are great for when the site actually returns a response of some kind. But I can't figure out how to handle a no response situation in some way, like simply posting a log message that it was a timeout.
I'm more used to scripts that use if/else statements; easier to read and interpret what is happening. I'm having trouble understanding the syntax for HTTPBuilder. I've been nosing around this page: HTTPBuilder (REST Assured 3.2.0 API) (javadoc.io)
Any help is greatly appreciated! And thanks again for getting me this far.
http.request(Method.GET) { req ->
response.success = {
HttpResponseDecorator resp, data ->
logger.info ("PINGBOT SUCCESS - Issue: ${mutableIssue} Site: ${issueSiteCheckURL} Status: ${resp.getStatusLine().getStatusCode()}");
//for now, just logging
//eventually adding the Jira actions here
}
response.failure = {
HttpResponseDecorator resp ->
logger.info ("PINGBOT FAILED - Issue: ${mutableIssue} Site: ${issueSiteCheckURL} Status: ${resp.getStatusLine().getStatusCode()}");
//for now, just logging
//eventually adding the Jira actions here
}
//not sure how to add additional logic to handle timeouts
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Timothy,
This should get you started.
import org.apache.http.client.config.RequestConfig
// You may want to consider different timeouts
def TIMEOUT = 10000
def requestCfg = RequestConfig
.custom()
.setConnectionRequestTimeout(TIMEOUT)
.setConnectTimeout(TIMEOUT)
.setSocketTimeout(TIMEOUT)
.build()
def http = new HTTPBuilder(host)
http.setClient(
HttpClients.custom()
.setDefaultRequestConfig(requestCfg)
.build()
)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One can do different things for different errors as well.
HTTPBuilder http = new HTTPBuilder(host)
http.request(Method.POST, ContentType.JSON) { req ->
response.success = { HttpResponseDecorator resp, data ->
// Alls well that ends well
}
response.'400' = { HttpResponseDecorator resp ->
// Do something
}
response.'404' = { HttpResponseDecorator resp ->
// Do something else
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To monitor websites externally in Jira, leverage ScriptRunner with Automation plugins. Schedule a script to check sites hourly. If the website response isn't 200, create a new issue in Jira with details. Organize issues with parent tasks for websites and subtasks for issues. Utilize Groovy with Adaptivist Library and community posts for scripting assistance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Automation plugin is not required as Scriptrunner already has the ability to schedule tasks and even create the issue right there in the same script.
I truly feel like monitoring in Jira is like taking a ferrari off road or competing in F1 with a Jeep :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Graham,
That response was from a spam bot.
But yes, I totally agree.
Jira is not a monitoring, or even alerting tool. It's the place to create a task to get a team to look at it, and track their response, arguably part of your monitoring system, but not the actual core of the monitoring.
Even the most simple monitoring I do is done with a set of tools suited for monitoring, all set up to raise issues in Jira if they spot certain problems (and usually another system for alerting)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've been hitting nails with my Jira hammer for a while, this is just the latest example. Non-standard use cases are my jam. :-)
Everyone is totally correct. This is not the proper way to do monitoring & alerting. There are just some very unique circumstances for why I this is valuable to my organization, but I won't bore Nic the Great with those details now.
I did get a simple version of the monitoring set up, and it ain't half bad, although not something I'd brag about yet. If I ever get time to polish it, I'll do a whole write up and share it.
Stay classy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Timothy Rynerwhat was the solution. You didn't accept any of these proposals ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How inconsiderate of me! Again, thanks for helping me down the path!
Here's the gist of what's running now. Again, this isn't polished, but it does do what I need, with some limitations.
I needed to pause work about 8 months ago (thanks to uptick in vulnerabilities keeping everyone on their toes), so I don't remember what the odd behaviors were that I wanted to improve. 401 auth redirects were one issue, I think. I fiddled with passing authentication creds along with the request, or to handle specific response codes...but I can't remember why I couldn't get that to fully work the way I want.
Anyway, it checks a few dozen simple sites that some teams manage, and works well enough for that. We're all in Jira all day, so it's nice getting notified there.
When I circle back on this to polish it, I'll do a nice write up. :-)
try {
http.request(Method.GET) { req ->
response.success = { HttpResponseDecorator resp, data ->
logger.info("Success response for Issue: ${mutableIssue} Site: ${siteCheckURL}")
int statusCode = resp.getStatusLine().getStatusCode()
def fieldConfig = siteEventField.getRelevantConfig(mutableIssue)
def option = ComponentAccessor.optionsManager.getOptions(fieldConfig).find { it.value == statusCode.toString() }
mutableIssue.setCustomFieldValue(siteLogsField, statusCode.toString())
if (option && (currentEventValue == null || !currentEventValue.contains(option))) {
mutableIssue.setCustomFieldValue(siteEventField, [option])
issueManager.updateIssue(scriptUser, mutableIssue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false)
logger.info("Updated Event field for Issue: ${mutableIssue} with Status Code: ${statusCode}")
}
}
response.failure = { HttpResponseDecorator resp ->
int statusCode = resp.getStatusLine().getStatusCode()
def fieldConfig = siteEventField.getRelevantConfig(mutableIssue)
def option = ComponentAccessor.optionsManager.getOptions(fieldConfig).find { it.value == statusCode.toString() }
mutableIssue.setCustomFieldValue(siteLogsField, statusCode.toString())
if (option && (currentEventValue == null || !currentEventValue.contains(option))) {
mutableIssue.setCustomFieldValue(siteEventField, [option])
issueManager.updateIssue(scriptUser, mutableIssue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false)
logger.info("Updated Event field for Issue: ${mutableIssue} with Status Code: ${statusCode}")
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I’m Madeleine, the Product Manager of a new ScriptRunner for integrations app by Adaptavist called Stitch It.
As the others have said, Jira may not be an optimal monitoring tool. If you do however decide to proceed with your implementation Stitch It could facilitate this for you (and any other integrations you might need between your bespoke tools and your Jira On-Premise).
We don’t have a bespoke template (Stitch It equivalent to a ScriptRunner Library script) that does exactly what you need, but we have a template that demonstrated how to hit a URL and inspect the status code and a template to create an issue in Jira on-prem, if you look at these templates hopefully you can stitch together a script and hook them up with our scheduled trigger to run your integration periodically. In case you need to connect to Jira on-prem instance behind the firewall, here are instructions on how to achieve it.
If you want to learn more about Stitch It you can also head over to our website here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is a neat tool! I work in an interesting environment with many of the exact issues outlined in the marketing slick. Now knowing this exists, I'll look at our processes through a different lens, and I might see about getting funding. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great, I'm very glad to hear it! You can test the app for free for a few more months until we come out of Beta, otherwise feel free to contact us via the website or via email directly (mvironda@adaptavist.com) and we'd be happy to arrange a demo!
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.