librenms / librenms-agent

LibreNMS Agent & Scripts
GNU General Public License v2.0
117 stars 188 forks source link

Add systemd.py script. Single-line style fix to pwrstatd.py. #424

Closed bnerickson closed 1 year ago

bnerickson commented 1 year ago

The primary purpose of this PR is introducing a systemd.py script to parse systemctl output and return the unit states to LibreNMS for ingestion into a new systemd application (PR to be submitted soon). Attached an image of what the app will look like.

Example JSON output by script exection:

{
  "errorString": "",
  "error": 0,
  "version": 1,
  "data": {
    "load": {
      "stub": 0,
      "loaded": 152,
      "not-found": 0,
      "bad-setting": 0,
      "error": 0,
      "merged": 0,
      "masked": 0,
      "total": 152
    },
    "active": {
      "active": 152,
      "reloading": 0,
      "inactive": 0,
      "failed": 0,
      "activating": 0,
      "deactivating": 0,
      "maintenance": 0,
      "total": 152
    },
    "sub": {
      "automount": {
        "dead": 0,
        "waiting": 1,
        "running": 0,
        "failed": 0,
        "total": 1
      },
      "device": {
        "dead": 0,
        "tentative": 0,
        "plugged": 22,
        "total": 22
      },
      "freezer": {
        "running": 0,
        "freezing": 0,
        "frozen": 0,
        "thawing": 0,
        "total": 0
      },
      "mount": {
        "dead": 0,
        "mounting": 0,
        "mounting-done": 0,
        "mounted": 13,
        "remounting": 0,
        "unmounting": 0,
        "remounting-sigterm": 0,
        "remounting-sigkill": 0,
        "unmounting-sigterm": 0,
        "unmounting-sigkill": 0,
        "failed": 0,
        "cleaning": 0,
        "total": 13
      },
      "path": {
        "dead": 0,
        "waiting": 2,
        "running": 0,
        "failed": 0,
        "total": 2
      },
      "scope": {
        "dead": 0,
        "start-chown": 0,
        "running": 3,
        "abandoned": 0,
        "stop-sigterm": 0,
        "stop-sigkill": 0,
        "failed": 0,
        "total": 3
      },
      "service": {
        "dead": 0,
        "condition": 0,
        "start-pre": 0,
        "start": 0,
        "start-post": 0,
        "running": 37,
        "exited": 25,
        "reload": 0,
        "stop": 0,
        "stop-watchdog": 0,
        "stop-sigterm": 0,
        "stop-sigkill": 0,
        "stop-post": 0,
        "final-watchdog": 0,
        "final-sigterm": 0,
        "final-sigkill": 0,
        "failed": 0,
        "auto-restart": 0,
        "cleaning": 0,
        "total": 62
      },
      "slice": {
        "dead": 0,
        "active": 10,
        "total": 10
      },
      "socket": {
        "dead": 0,
        "start-pre": 0,
        "start-chown": 0,
        "start-post": 0,
        "listening": 5,
        "running": 6,
        "stop-pre": 0,
        "stop-pre-sigterm": 0,
        "stop-pre-sigkill": 0,
        "stop-post": 0,
        "final-sigterm": 0,
        "final-sigkill": 0,
        "failed": 0,
        "cleaning": 0,
        "total": 11
      },
      "swap": {
        "dead": 0,
        "activating": 0,
        "activating-done": 0,
        "active": 1,
        "deactivating": 0,
        "deactivating-sigterm": 0,
        "deactivating-sigkill": 0,
        "failed": 0,
        "cleaning": 0,
        "total": 1
      },
      "target": {
        "dead": 0,
        "active": 23,
        "total": 23
      },
      "timer": {
        "dead": 0,
        "waiting": 4,
        "running": 0,
        "elapsed": 0,
        "failed": 0,
        "total": 4
      }
    }
  }
}
systemd