I have the following preprocessing Javascript rule for a custom template I'm creating to monitor systemd services on Linux:
The resulting JSON data is as expected, where UNIT.ACTIVESTATE is now a combination of ActiveState and SubState:
However, in my Item prototype, when I poll for systemd.unit.info["{#UNIT.NAME}.service"] it still returns just ActiveState and not the combination that I preprocessed for. It was my understanding that Items would take from the data pulled from Discovery, it seems like this key is just doing another separate poll. Any ideas on how to get the data I already polled for from Discovery?
Code:
my_dict = JSON.parse(value);
var output_dict = [];
for (var index in my_dict) {
// Only pull keys you want to modify
service_name = my_dict[index]['{#UNIT.NAME}'];
active_state = my_dict[index]['{#UNIT.ACTIVESTATE}'];
sub_state = my_dict[index]['{#UNIT.SUBSTATE}'];
// Remove .service from systemd name (looks ugly as an Item name in Zabbix).
my_dict[index]['{#UNIT.NAME}'] = service_name.replace('.service', '');
// Modify the value of ActiveState to include the substate of a systemd service.
my_dict[index]['{#UNIT.ACTIVESTATE}'] = active_state + " (" + sub_state + ")";
}
return JSON.stringify(my_dict);
Code:
{
"{#UNIT.NAME}": "loadmodules",
"{#UNIT.DESCRIPTION}": "Load legacy module configuration",
"{#UNIT.LOADSTATE}": "loaded",
"{#UNIT.ACTIVESTATE}": "inactive (dead)",
"{#UNIT.SUBSTATE}": "dead",
"{#UNIT.FOLLOWED}": "",
"{#UNIT.PATH}": "/org/freedesktop/systemd1/unit/loadmodules_2eservice",
"{#UNIT.JOBID}": 0,
"{#UNIT.JOBTYPE}": "",
"{#UNIT.JOBPATH}": "/",
"{#UNIT.UNITFILESTATE}": "enabled"
}
Comment