I am trying to make an API call from Script runner script consoles to fill in a field in Zabbix. Now I'm just testing, and I get this error:
groovyx.net.http.ResponseParseException: status code: 412, reason phrase: Precondition Failed at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:495) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:434) at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:383) at groovyx.net.http.HTTPBuilder$request.call(Unknown Source) at Script974.run(Script974.groovy:21) Caused by: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object The current character read is '' with an int value of 0 Unable to determine the current character, it is not a string, number, array, or object line number 1 index number 255 ...............................................................................................................................................................................................................................................................^ at org.apache.groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:202) at org.apache.groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:153) at org.apache.groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:43) at org.apache.groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:380) at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:131) at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:280) at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:560) at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:489) ... 7 more
The script I use:
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.json.JsonOutput
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import groovyx.net.http.Method
import static groovyx.net.http.Method.PATCH
// def http = new HTTPBuilder('https://serviceportal.pornhub.local:443/')
def body = [ "jsonrpc": "2.0", "method": "apiinfo.version", "id": "1","auth": "null", "params": {}]
def url ="http://192.168.1.2/"
def endpoint = "/api_jsonrpc.php"
def returnResponse
def httpBuilder = new HTTPBuilder(url)
httpBuilder.request(POST, ContentType.JSON) {
headers.contentType = "ContentType: application/json"
uri.path = endpoint
body = body
response.success = { resp, JSON ->
log.warn("Successful = " + JSON)
}
response.failure = { resp, JSON ->
log.warn("Failed = " + JSON)
}
}
I am not very well versed in Jira and scripting, I will be very grateful for help
Most of this error message is about the httpbuilder not being able to parse this response into a JSON.
But the root cause of it is that you didn't receive a valid JSON from your endpoint, probably because you didn't send a valid request.
The first line gives you some clues: "412, reason phrase: Precondition Failed"
This means that the endpoint returned a status 412 error and you need to figure out what this means from zabbix and figure out what jira sent or didn't send that zabbix expected.
Try removing ContentType.JSON for testing so that you won't get automatic parsing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.