SMART Application monitor script having problems parsing json

I am trying to setup SMART monitoring on some servers. I have setup the following smart.config file:

cache=/var/cache/smart
smartctl=/usr/bin/env smartctl
useSN=0
sdb
sdc

So, it’s not too complicated. However, the UI in LibreNMS just shows:

All Drives | drives: {“data”:{“dev_error”:0

Sure enough, If I just run ‘/etc/snmp/smart’, I get this output:

{“data”:{“dev_error”:0,“disks”:{“sdb”:{“10”:null,“12”:null,“173”:null,“177”:null,“183”:null,“184”:null,“187”:null,“188”:null,“190”:null,“194”:null,“196”:null,“197”:null,“198”:null,“199”:null,“231”:null,“232”:null,“233”:null,“5”:null,“9”:null,“dev_error”:0,“disk”:“sdb”,“exit”:32512,“health_pass”:0,“json_err”:1,“json_err_str”:“malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before “(end of string)”) at /etc/snmp/smart line 665.\n”,“max_temp”:null,“over_temp”:0,“selftest_log”:null,“serial”:null,“temp_limit”:null},“sdc”:{“10”:null,“12”:null,“173”:null,“177”:null,“183”:null,“184”:null,“187”:null,“188”:null,“190”:null,“194”:null,“196”:null,“197”:null,“198”:null,“199”:null,“231”:null,“232”:null,“233”:null,“5”:null,“9”:null,“dev_error”:0,“disk”:“sdc”,“exit”:32512,“health_pass”:0,“json_err”:1,“json_err_str”:“malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before “(end of string)”) at /etc/snmp/smart line 665.\n”,“max_temp”:null,“over_temp”:0,“selftest_log”:null,“serial”:null,“temp_limit”:null}},“exit_nonzero”:2,“unhealthy”:0,“useSN”:“0”},“error”:0,“errorString”:“”,“version”:1}

If I run ‘smartctl -a /dev/sdb’ manually, it seems to work just fine and gives me lots of data.

It seems like the smart script is having problems parsing the json from smartctl.
Anybody ever seen this? My system is running Almalinux 8.10. Smartctl is version 7.1.

OK, after a bunch of troubleshooting, I figured out a few things:

  1. I had entered the snmp extend configuration part in snmpd.conf incorrectly. I had entered this:

extend smart /bin/cat /var/cache/smart

No idea why I did that, the instructions in the smart script, AND on the LibreNMS Docs site both say to do this:

extend smart /bin/cat /var/cache/smart.snmp

The ‘.snmp’ file is compressed, which I guess is what SNMP is expecting. :slight_smile:

  1. I also figured out that the cron job to run the update of the smart cache doesn’t need the ‘-Z’ parameter, it does the compressed file even if you leave that off.

I still seem to have a problem, however. The cron job - when it runs, it produces a JSON error. However, when I login an run the same command as root from the command-line, there is no JSON error. hm…

YES! I proved this is the problem. If I run the cron command in the command-line, and then disable the cron job, the data shows up in LibreNMS GUI! However, if I let the CRON job run, I get JSON errors…

My fix for this is to run the script as a systemd timer, instead of a cron job. Running as a systemd timer, I now have no JSON errors.

I never did figure out why cron can’t do this…something about PERL running as cron job as root and not have same permissions/environment as the command line.

However - when running this as a systemd timer, all works great.

Here’s the timer file I created (I named it snmp-smart.timer) :

[Unit]
Description=Run SMART Update for SNMP Extend

[Timer]
OnBootSec=1min
OnUnitActiveSec=5min
AccuracySec=1s
Unit=snmp-smart.service

[Install]
WantedBy=multi-user.target

This also requires a service file (I named is snmp-smart.service):

[Unit]
Description=SMART Update of Cache for SNMP Monitoring

[Service]
Type=oneshot
User=root
Group=root
ExecStart=/etc/snmp/smart -u

[Install]
WantedBy=multi-user.target

I then placed these in /etc/systemd/system, and ran these commands:

systemctl enable snmp-smart.timer
systemctl start snmp-smart.timer
systemctl status snmp-smart.timer

Viewing the status, you should see the ‘trigger’ line of output is counting down until the next run of the timer:

[root@gmctest6vdb system]# systemctl status snmp-smart.timer
● snmp-smart.timer - Run SMART Update for SNMP Extend
Loaded: loaded (/etc/systemd/system/snmp-smart.timer; enabled; vendor preset: disabled)
Active: active (waiting) since Wed 2026-04-22 11:31:23 CDT; 10min ago
Trigger: Wed 2026-04-22 11:46:24 CDT; 4min 45s left

Apr 22 11:31:23 gmctest6vdb.dev.oati.local systemd[1]: Started Run SMART Update for SNMP Extend.

Then if you run the ‘status’ command repeatedly, that will count down until it runs.

Now, my /var/cache/smart file has no JSON errors.