Trying to integrate Zabbix into our Freshserivce instance
Following these instructions to the letter
Step 1 - says to create a media type, which I did, exactly as the instructions above instructed. I even deleted it and re-did it again, just to double check and I receive the exact same error each time.
Googling it, it seems to be an error with the 'fields' variable but I have no idea how to fix it. Below is the supplied script from the link above.
Please assist, thank you.
Following these instructions to the letter
Step 1 - says to create a media type, which I did, exactly as the instructions above instructed. I even deleted it and re-did it again, just to double check and I receive the exact same error each time.
Media type test failed.
- ReferenceError: identifier 'fields' undefined at [anon] (duktape.c:83867) internal at [anon] (function:115) preventsyield
Code:
try {
Zabbix.Log(4, 'webhook script value=' + value);
var result = {
'tags': {
'endpoint': 'FS_AMS'
}
};
params = JSON.parse(value);
var tags_array = [];
if (params.tags != "" && params.tags != "{EVENT.TAGS}") {
tags = params.tags.split(",");
for(i = 0; i < tags.length; i++) {
tags_array.push(tags[i].trim());
}
}
req = new CurlHttpRequest();
fields = {
"message": params.message,
"subject": params.subject,
"item_key": params.item_key,
"host_ip": params.host_ip,
"event_name": params.event_name,
"hostname": params.hostname,
"event_opdata": params.event_opdata,
"severity": params.severity,
"item_name": params.item_name,
"event_status": params.event_status,
"action_id": params.action_id,
"action_name": params.action_name,
"event_date": params.event_date,
"event_time": params.event_time,
"event_age": params.event_age,
"tags": tags_array
};
if(params.event_status == "RESOLVED") {
fields.severity = "ok";
}
resp = '';
req.AddHeader('Content-Type: application/json');
req.AddHeader('Authorization: ' + params.auth_key);
resp = req.Post(params.url, JSON.stringify(fields));
if (req.Status() != 202) {
throw 'Response code: ' + req.Status();
}
else {
results = JSON.stringify({"response_body": resp });
Zabbix.Log(4, results);
}
return results;
}
catch(error) {
Zabbix.Log(4, 'FS AMS Notification failed: ' + JSON.stringify({ "fields": fields }));
Zabbix.Log(4, 'FS AMS alert creation failed : ' + error);
results = JSON.stringify({"error": error});
return results;
}
Comment