Skip to content

Commit 46924b3

Browse files
committed
agent configuration
1 parent 685c564 commit 46924b3

File tree

6 files changed

+76
-62
lines changed

6 files changed

+76
-62
lines changed

agent_based/proxmox_bs.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,27 +129,33 @@ def proxmox_bs_checks(item, params, section):
129129
yield Metric('total_backups', n)
130130
if (n == "proxmox-backup-client snapshot list") and (k == item):
131131
nr, np, ok, nok = 0, [], 0, []
132-
for e in json.loads(c):
133-
if "verification" in e:
134-
verify_state = e.get("verification", {}).get("state", "na")
135-
if verify_state == "ok":
136-
ok = ok+1
137-
elif verify_state == "failed":
138-
nok.append(e)
132+
try:
133+
for e in json.loads(c):
134+
if "verification" in e:
135+
verify_state = e.get("verification", {}).get("state", "na")
136+
if verify_state == "ok":
137+
ok = ok+1
138+
elif verify_state == "failed":
139+
nok.append(e)
140+
else:
141+
np.append(e)
139142
else:
140-
np.append(e)
141-
else:
142-
nr = nr+1
143-
yield Metric('verify_ok', ok)
144-
yield Metric('verify_failed', len(nok))
145-
yield Metric('verify_unknown', len(np))
146-
yield Metric('not_verified_yet', nr)
147-
yield Result(state=State.OK, summary=(
148-
'Snapshots Verified: %d' % ok
149-
))
150-
yield Result(state=State.OK, summary=(
151-
'Snapshots not verified yet: %d' % nr
152-
))
143+
nr = nr+1
144+
yield Metric('verify_ok', ok)
145+
yield Metric('verify_failed', len(nok))
146+
yield Metric('verify_unknown', len(np))
147+
yield Metric('not_verified_yet', nr)
148+
yield Result(state=State.OK, summary=(
149+
'Snapshots Verified: %d' % ok
150+
))
151+
yield Result(state=State.OK, summary=(
152+
'Snapshots not verified yet: %d' % nr
153+
))
154+
except:
155+
yield Result(
156+
state=State.WARN,
157+
summary='snapshot parsing error',
158+
)
153159
for e in np:
154160
group = '%s/%s' % (e["backup-type"], e["backup-id"])
155161
stat = e["verification"]["state"]

agents/plugins/proxmox_bs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ proxmox-backup-client
2727
jq
2828
.
2929

30-
$(< /etc/check_mk/proxmox_bs.env)
31-
3230
command_section() {
3331
PIPE=
3432
SECTION_POSTFIX=
@@ -53,6 +51,10 @@ command_section() {
5351
sh -c "$cmd $* $PIPE"
5452
}
5553

54+
$(< /etc/check_mk/proxmox_bs.env)
55+
PBS_REPO="${PBS_USERNAME}@localhost"
56+
proxmox-backup-client login
57+
5658
OUTPUT_FORMAT="--output-format json-pretty"
5759

5860
command_section "proxmox-backup-manager versions" $OUTPUT_FORMAT
@@ -72,12 +74,12 @@ jq -r '.[].name' $TMP_DATASTORES | while read -r name; do
7274
"proxmox-backup-manager garbage-collection status" $name $OUTPUT_FORMAT
7375
jq -r '.upid' "$TMP_GC" >> $TMP_UPIDS
7476
command_section -p "$name" \
75-
"proxmox-backup-client list" --repository "localhost:$name" $OUTPUT_FORMAT
77+
"proxmox-backup-client list" --repository "$PBS_REPO:$name" $OUTPUT_FORMAT
7678
command_section -p "$name" \
77-
"proxmox-backup-client snapshot list" --repository "localhost:$name" \
79+
"proxmox-backup-client snapshot list" --repository "$PBS_REPO:$name" \
7880
$OUTPUT_FORMAT
7981
command_section -p "$name" \
80-
"proxmox-backup-client status" --repository "localhost:$name" \
82+
"proxmox-backup-client status" --repository "$PBS_REPO:$name" \
8183
$OUTPUT_FORMAT
8284
done
8385

@@ -86,7 +88,7 @@ cat $TMP_UPIDS | while read -r upid; do
8688
"proxmox-backup-manager task log" "$upid"
8789
done
8890

89-
proxmox-backup-client logout --repository "localhost"
91+
proxmox-backup-client logout --repository "$PBS_REPO"
9092
export PBS_PASSWORD=
9193

9294
printf "$TMP_GC_FILES" >> $TMP_GC_FILES

info

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
'download_url': '',
44
'files': {'agent_based': ['proxmox_bs.py'],
55
'agents': ['plugins/proxmox_bs'],
6-
'lib': ['check_mk/base/cee/plugins/bakery/proxmox_bs.py',
7-
'python3/cmk/base/cee/plugins/bakery/proxmox_bs.py'],
6+
'lib': ['check_mk/base/cee/plugins/bakery/proxmox_bs.py'],
87
'web': ['plugins/wato/proxmox_bs.py']},
98
'name': 'proxmox_bs',
10-
'num_files': 5,
9+
'num_files': 4,
1110
'title': 'Proxmox Backup Server',
12-
'version': '0.1.19',
11+
'version': '0.3.0',
1312
'version.min_required': '2.0.0',
1413
'version.packaged': '2.0.0p3',
1514
'version.usable_until': None}

lib/check_mk/base/cee/plugins/bakery/proxmox_bs.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@
44
from pathlib import Path
55
from typing import Any, Dict
66

7-
from .bakery_api.v1 import FileGenerator, OS, Plugin, register
7+
from .bakery_api.v1 import (
8+
FileGenerator,
9+
OS,
10+
Plugin,
11+
PluginConfig,
12+
register,
13+
)
814

915

1016
def get_proxmox_bs_files(conf: Dict[str, Any]) -> FileGenerator:
11-
if conf == 'server':
17+
if conf != None:
1218
yield Plugin(base_os=OS.LINUX, source=Path("proxmox_bs"))
13-
elif conf == 'client':
14-
yield Plugin(base_os=OS.LINUX, source=Path("proxmox_bs_client"))
19+
yield PluginConfig(
20+
base_os=OS.LINUX,
21+
lines=[
22+
"export PBS_USERNAME=%s" % conf.get('auth_user'),
23+
"export PBS_PASSWORD=%s" % conf.get('auth_pass'),
24+
],
25+
target=Path("proxmox_bs.env"),
26+
)
1527

1628

1729
register.bakery_plugin(

lib/python3/cmk/base/cee/plugins/bakery/proxmox_bs.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

web/plugins/wato/proxmox_bs.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,34 @@
1616
RulespecGroupMonitoringAgentsAgentPlugins
1717
)
1818
from cmk.gui.valuespec import (
19-
DropdownChoice,
19+
Alternative,
20+
Dictionary,
21+
FixedValue,
22+
Password,
23+
TextInput,
2024
)
2125

2226

2327
def _valuespec_agent_config_proxmox_bs():
24-
return DropdownChoice(
28+
return Alternative(
2529
title = _("Proxmox Backup Server (Linux)"),
26-
help = _("This will deploy the agent plugin <tt>proxmox_bs</tt>"),
27-
choices = [
28-
( 'server', _("Deploy plugin for Proxmox Backup Server") ),
29-
( 'client', _("Deploy plugin for Proxmox Backup Client only")),
30-
( None, _("Do not deploy plugin for Proxmox Backup") ),
31-
]
30+
help = _("Proxmox Backup Server Monitoring (<tt>proxmox_bs</tt>)"),
31+
style = 'dropdown',
32+
elements = [
33+
Dictionary(
34+
title = _("Deploy Proxmox Backup Server plugin"),
35+
elements = [
36+
( 'auth_user', TextInput(title=_("Username")) ),
37+
( 'auth_pass', Password(title=_("Password")) ),
38+
],
39+
optional_keys = [],
40+
),
41+
FixedValue(
42+
None,
43+
title = _("Do not deploy plugin for Proxmox Backup server"),
44+
totext = _("(disabled)"),
45+
)
46+
],
3247
)
3348

3449

0 commit comments

Comments
 (0)