Open otheus opened 3 years ago
Also, I refactored the other script into a nicer more efficient pipeline, but it shaves only 1% of execution time at best. I then did it in perl for a 1.01% speed-up! Here's the SH pipeline version.
extract_enabled_service_names() {
awk -F'[. \t]+' '$2 == "service" && $3 ~ "^(generated|enabled)" {print $1}'
}
include_whitelist_only() {
if [[ -r /etc/zabbix/service_discovery_whitelist ]] ; then
grep -E -f /etc/zabbix/service_discovery_whitelist
else cat; fi
}
exclude_blacklist() {
if [[ -r /etc/zabbix/service_discovery_blacklist ]] ; then
grep -Ev -f /etc/zabbix/service_discovery_blacklist
else cat; fi
}
convert_to_json() {
awk 'BEGIN { print "{\"data\":["; } NR>1 { printf(",");} { printf("{\"{#SERVICE}\": \"%s\"}",$0) } END { print "]}" } '
}
systemctl list-unit-files |
extract_enabled_service_names |
include_whitelist_only |
exclude_blacklist |
convert_to_json
It would be in most circumstances better to get the actual timestamp of the last time the service was restarted. Unfortunately, Zabbix' custom params does not know how to handle exception data other than making the service unavilable, so 0 probably makes sense. HEre is my implementation, based on your check-status script: