inettgmbh / checkmk-proxmox_backup_server

check_mk extension package for Proxmox Backup Server
https://www.inett.de/it-loesungen/checkmk
GNU General Public License v2.0
8 stars 5 forks source link

How to install the plugin on the pbs server? #7

Closed peterge1998 closed 8 months ago

peterge1998 commented 8 months ago

We use cmk raw edition. Installing the mkp works just fine, but when installing this to /usr/lib/check_mk_agent/plugins/proxmox_bs.py i get this error:

root@pbsbn:/usr/lib/check_mk_agent/plugins# ./proxmox_bs.py 
<<<proxmox_bs>>>
===requirements===
0 proxmox-backup-manager
0 proxmox-backup-client
0 jq
./proxmox_bs.py: line 61: /etc/check_mk/proxmox_bs.env: No such file or directory
Error: unable to get (default) repository
===proxmox-backup-manager versions===
/bin/env proxmox-backup-manager versions --output-format json-pretty
[
  {
    "Arch": "amd64",
    "Description": "Proxmox Backup Server daemon with tools and GUI\n This package contains the Proxmox Backup Server daemons and related\n tools. This includes a web-based graphical user interface.",
    "ExtraInfo": "running version: 3.1.4",
    "OldVersion": "3.1.4-1",
    "Origin": "Proxmox",
    "Package": "proxmox-backup-server",
    "Priority": "optional",
    "Section": "admin",
    "Title": "Proxmox Backup Server daemon with tools and GUI",
    "Version": "3.1.4-1"
  }
]
===proxmox-backup-manager datastore list===
/bin/env proxmox-backup-manager datastore list --output-format json-pretty | tee /tmp/tmp.7yBECcCj9P
[
  {
    "comment": "",
    "gc-schedule": "daily",
    "name": "DasiBN",
    "path": "/mnt/pve/DasiBN/proxmox-backup-server"
  }
]
===proxmox-backup-manager task list===
/bin/env proxmox-backup-manager task list --output-format json-pretty
[
  {
    "node": "localhost",
    "pid": 803,
    "pstart": 510,
    "starttime": 1709122247,
    "upid": "UPID:pbsbn:00000323:000001FE:00000008:65DF22C7:termproxy::root@pam:",
    "user": "root@pam",
    "worker_id": null,
    "worker_type": "termproxy"
  }
]
===proxmox-backup-manager garbage-collection status===DasiBN
/bin/env proxmox-backup-manager garbage-collection status DasiBN --output-format json-pretty | tee /tmp/tmp.lv3xshfGdq
{
  "disk-bytes": 2419293387,
  "disk-chunks": 1276,
  "index-data-bytes": 72509286101,
  "index-file-count": 6,
  "pending-bytes": 158,
  "pending-chunks": 1,
  "removed-bad": 0,
  "removed-bytes": 855087331,
  "removed-chunks": 728,
  "still-bad": 0,
  "upid": "UPID:pbsbn:0000038D:00000208:00000020:65DF1954:garbage_collection:DasiBN:root@pam:"
root@pbsbn:/usr/lib/check_mk_agent/plugins# ./proxmox_bs.py 
<<<proxmox_bs>>>
===requirements===
0 proxmox-backup-manager
0 proxmox-backup-client
0 jq
./proxmox_bs.py: line 61: /etc/check_mk/proxmox_bs.env: No such file or directory
Error: unable to get (default) repository
===proxmox-backup-manager versions===
/bin/env proxmox-backup-manager versions --output-format json-pretty
[
  {
    "Arch": "amd64",
    "Description": "Proxmox Backup Server daemon with tools and GUI\n This package contains the Proxmox Backup Server daemons and related\n tools. This includes a web-based graphical user interface.",
    "ExtraInfo": "running version: 3.1.4",
    "OldVersion": "3.1.4-1",
    "Origin": "Proxmox",
    "Package": "proxmox-backup-server",
    "Priority": "optional",
    "Section": "admin",
    "Title": "Proxmox Backup Server daemon with tools and GUI",
    "Version": "3.1.4-1"
  }
]
===proxmox-backup-manager datastore list===
/bin/env proxmox-backup-manager datastore list --output-format json-pretty | tee /tmp/tmp.ndM7zHEULF
[
  {
    "comment": "",
    "gc-schedule": "daily",
    "name": "DasiBN",
    "path": "/mnt/pve/DasiBN/proxmox-backup-server"
  }
]
===proxmox-backup-manager task list===
/bin/env proxmox-backup-manager task list --output-format json-pretty
[
  {
    "node": "localhost",
    "pid": 803,
    "pstart": 510,
    "starttime": 1709122247,
    "upid": "UPID:pbsbn:00000323:000001FE:00000008:65DF22C7:termproxy::root@pam:",
    "user": "root@pam",
    "worker_id": null,
    "worker_type": "termproxy"
  }
]
===proxmox-backup-manager garbage-collection status===DasiBN
/bin/env proxmox-backup-manager garbage-collection status DasiBN --output-format json-pretty | tee /tmp/tmp.aiWH8ztPte
{
  "disk-bytes": 2419293387,
  "disk-chunks": 1276,
  "index-data-bytes": 72509286101,
  "index-file-count": 6,
  "pending-bytes": 158,
  "pending-chunks": 1,
  "removed-bad": 0,
  "removed-bytes": 855087331,
  "removed-chunks": 728,
  "still-bad": 0,
  "upid": "UPID:pbsbn:0000038D:00000208:00000020:65DF1954:garbage_collection:DasiBN:root@pam:"
}
===proxmox-backup-client list===DasiBN
/bin/env proxmox-backup-client list --repository @localhost:DasiBN --output-format json-pretty
Error: parameter verification failed - 'repository': value does not match the regex pattern
Usage: proxmox-backup-client list [OPTIONS]
Optional parameters:

 --ns       <string>
             Namespace.

 --output-format text|json|json-pretty
             Output format.

 --repository <string>
             Repository URL.

===proxmox-backup-client snapshot list===DasiBN
/bin/env proxmox-backup-client snapshot list --repository @localhost:DasiBN --output-format json-pretty
Error: parameter verification failed - 'repository': value does not match the regex pattern
Usage: proxmox-backup-client snapshot list [<group>] [OPTIONS]
 <group>    <string>
             Backup group.

Optional parameters:

 --ns       <string>
             Namespace.

 --output-format text|json|json-pretty
             Output format.

 --repository <string>
             Repository URL.

===proxmox-backup-client status===DasiBN
/bin/env proxmox-backup-client status --repository @localhost:DasiBN --output-format json-pretty
Error: parameter verification failed - 'repository': value does not match the regex pattern
Usage: proxmox-backup-client status [OPTIONS]
Optional parameters:

 --output-format text|json|json-pretty
             Output format.

 --repository <string>
             Repository URL.

===proxmox-backup-manager task log===UPID:pbsbn:0000038D:00000208:00000020:65DF1954:garbage_collection:DasiBN:root@pam:
/bin/env proxmox-backup-manager task log UPID:pbsbn:0000038D:00000208:00000020:65DF1954:garbage_collection:DasiBN:root@pam: 2>&1 | sed '/^Removed /,$!d'
Removed garbage: 815.475 MiB
Removed chunks: 728
Pending removals: 158 B (in 1 chunks)
Original data usage: 67.53 GiB
On-Disk usage: 2.253 GiB (3.34%)
On-Disk chunks: 1276
Deduplication factor: 29.97
Average chunk size: 1.808 MiB
TASK OK
removed '/tmp/tmp.mN9jcgTapi'
===EOD===
=

When I ran it for the first time, it just said this:

root@pbsbn:/usr/lib/check_mk_agent/plugins# ./proxmox_bs.py 
<<<proxmox_bs>>>
===requirements===
0 proxmox-backup-manager
0 proxmox-backup-client
1 jq

But after running apt install jq, the requirements warning is gone.

Jay2k1 commented 8 months ago

It tells you

./proxmox_bs.py: line 61: /etc/check_mk/proxmox_bs.env: No such file or directory

So you need to create the /etc/check_mk/proxmox_bs.env file. The check needs API access, so go to configuration ➜ access control, click "API Token" and add one if you haven't already.

Fill the /etc/check_mk/proxmox_bs.env file with the API token details so it looks somewhat like this:

#!/bin/bash
export PBS_USERNAME=user@pam!tokenname
export PBS_PASSWORD=abcd1234-1234-abcd-1234-abcdef123456

It would be great if the project's README would list all these steps in the installation instructions instead of having users figure that out for themselves.

peterge1998 commented 8 months ago

Ah, makes sense to put the API token into the env file! Now it does not complain anymore.

I renamed the file to mk_proxmox_bs.py, to match the naming convention and permissions that another host with mk_docker.py has.

But the check is still not showing up when I run a service discovery on the pbs host - any idea why?

root@pbsbn:/usr/lib/check_mk_agent/plugins# ls -l
total 4
-rwxr-xr-x 1 root root 2851 Feb 28 13:20 mk_proxmox_bs.py

Regarding the project's README, a link to this issue should be enough for anyone to set it up :)

root@pbsbn:/usr/lib/check_mk_agent/plugins# check_mk_agent | grep plugin
PluginsDirectory: /usr/lib/check_mk_agent/plugins
<<<checkmk_agent_plugins_lnx:sep(0)>>>
pluginsdir /usr/lib/check_mk_agent/plugins
/usr/lib/check_mk_agent/plugins/mk_proxmox_bs.py:CMK_VERSION="unversioned"
Jay2k1 commented 8 months ago

Naming it .py does not make sense as it is not python but a bash script, so .sh (or no extension as suggested by the project and other bash scripts shipped with check_mk) would fit better. It should not make a difference though.

As for why the check does now show up, good question. The first thing I do is run the check manually on the command line, usually cd /usr/lib/check_mk_agent/plugins; ./myplugin. If that works, I run check_mk_agent > agentout.txt so I can examine what's going on. If it does not show up and I can't figure it out, I start debugging (adding a bunch of echos to a copy of the agent and running that).

peterge1998 commented 8 months ago

Just to document this here: I had to set 2 more things in the env file, the PBS_REPOSITORY and the PBS_FINGERPRINT because we used self signed certificates (forum post).

Now my env file looks like this:

#!/bin/bash
export PBS_USERNAME=root@pam!<tokenname>
export PBS_PASSWORD=<api-secret>
export PBS_REPOSITORY=localhost:<datastore>
export PBS_FINGERPRINT=<fingerprint>

I also had to set up the permissions for / for the user the token belongs to.

Now the check works fine: image

Thanks for making this plugin! <3

marcogabriel commented 7 months ago

Thanks for the feedback. I'll check if we can extend the docs.

peterge-misoft commented 2 months ago

And of course you need to install AND enable the mkp from the releases :)