mirror of
https://github.com/thegeeklab/prometheus-pve-sd.git
synced 2024-06-02 16:09:41 +02:00
Compare commits
420 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2f5661a529 | ||
|
f79e7a1248 | ||
|
2fd71a96c7 | ||
|
62c6d6fdb7 | ||
|
ac3ff2d9df | ||
|
7cdc20a555 | ||
|
8e71ce23e5 | ||
|
0577f10fad | ||
|
d023f7e9e9 | ||
|
762547a0da | ||
|
8d9d59351e | ||
|
8239461432 | ||
|
ff3f401786 | ||
|
04ce915e07 | ||
|
791c2482c0 | ||
|
2c7c767830 | ||
|
b7ec5ba60e | ||
|
658b9b2502 | ||
|
9bcc45932f | ||
|
d504297a08 | ||
|
e541271ffd | ||
|
9d26517a6b | ||
|
ff21ee3db6 | ||
|
e76f37f143 | ||
|
cc158dddf6 | ||
0590089098 | |||
|
d5cdd92242 | ||
|
e082d6c7cb | ||
|
7966c1c11e | ||
|
a2f513156a | ||
|
a2485d83eb | ||
|
4b3249b9a3 | ||
|
3f7d44a7d2 | ||
|
db8b62c323 | ||
|
bc05b2ad38 | ||
|
c324ab330f | ||
fa06bcbdf1 | |||
|
7b72b07157 | ||
ad9ffeab64 | |||
|
14788622c7 | ||
|
aed5373c06 | ||
7e7bd413a8 | |||
|
028d733d87 | ||
|
e5c599472b | ||
1c3e4fc7e7 | |||
|
aa3a82ae08 | ||
|
395623b08b | ||
|
76ec43e1f8 | ||
|
d470109ddc | ||
|
cae9a4d815 | ||
|
9b1a450b48 | ||
|
5cb73241f9 | ||
|
f39aea6c82 | ||
|
793ec14b80 | ||
|
55378ceea6 | ||
|
f3f9dac6fe | ||
|
f2b770d1f8 | ||
|
63ee9caf5d | ||
|
ebf54473bd | ||
|
8d7a30a0b1 | ||
|
1e3d5a0b18 | ||
|
e356f64bfd | ||
|
5c0c893915 | ||
88eac83007 | |||
3de899b6cd | |||
|
b603af1380 | ||
8c2b3ad968 | |||
|
a76a6f40e3 | ||
|
1dc51232cc | ||
b6fd9ccf83 | |||
|
3d85f78054 | ||
|
12e70d508d | ||
|
e244d4ddaf | ||
518f8d428b | |||
|
4811621be5 | ||
|
9d1ab01643 | ||
|
ba3456b53a | ||
|
ce708b94cb | ||
|
2088efbe23 | ||
f13de60e06 | |||
|
fd85dc598b | ||
0756afda02 | |||
|
2a3468b604 | ||
|
2baaf1e07b | ||
|
334caabe1f | ||
|
a1643b3a9f | ||
|
bb23593f5c | ||
|
42e0a5f726 | ||
|
b0cc925b55 | ||
|
5bc82508c8 | ||
|
c84035a405 | ||
|
da28d6dd9c | ||
|
1694771542 | ||
|
de9aac38ca | ||
|
72d0e49028 | ||
|
a5755e03af | ||
|
79c3e8683b | ||
628244f9ad | |||
8f6c394a21 | |||
e98439b9ff | |||
|
1d9a82d774 | ||
40bfa21f72 | |||
cb5fa8409e | |||
|
ab9d0de2f5 | ||
|
f957869179 | ||
|
ef86a0000e | ||
|
958c89f2f9 | ||
|
8e690232e3 | ||
bdd940131d | |||
|
bc7b5ebf47 | ||
|
a370bd26fd | ||
|
4bdfcc3256 | ||
|
ae62da0ec2 | ||
|
3b4707e06c | ||
4c35cc706c | |||
e5f3947e7c | |||
|
7096aefb74 | ||
|
3dc7405378 | ||
35bfa8bc6a | |||
|
a6d128d605 | ||
|
d7bc938ecb | ||
3eaf162858 | |||
|
5e7a371725 | ||
|
dcfdcb6272 | ||
|
74a5a67112 | ||
|
62d41df763 | ||
|
b88a9e0c55 | ||
99f426263b | |||
8be6b5b824 | |||
c7faac94e4 | |||
|
c8c1ba033d | ||
|
37440e080c | ||
202d19d8df | |||
|
7090981489 | ||
|
c55705d438 | ||
|
6608cc6a8a | ||
|
d3c07449c1 | ||
|
37f09b0ded | ||
|
ad39a58124 | ||
|
f802637149 | ||
|
91b3b5143b | ||
|
40ae246fc8 | ||
|
5e7e58cbd2 | ||
|
a38285a2c5 | ||
c6b1734ad1 | |||
|
8b99e80fce | ||
|
4f01e9fdb5 | ||
|
e8c72c63fc | ||
|
f2a87114c6 | ||
|
f29ac553ae | ||
2d415caca6 | |||
|
0700c91f00 | ||
|
9eb888fac8 | ||
|
31c0e1b166 | ||
|
63da0a31c4 | ||
|
bb1370f57c | ||
372911d63c | |||
a8b4ae4827 | |||
|
b3717c2b79 | ||
|
3c86756779 | ||
|
3e346c21ad | ||
|
94597d9a84 | ||
|
d70ff324a7 | ||
|
044ed59b05 | ||
|
a8af0597bd | ||
|
ae0e8fa87f | ||
|
3838826442 | ||
|
46ae2c79e0 | ||
|
8915a480c1 | ||
|
b00845735f | ||
|
5e9a3b2426 | ||
|
6e118aa4f9 | ||
|
553220aed0 | ||
111f856cea | |||
|
8dad3ae9dd | ||
|
edf8082b31 | ||
|
b0079e33f5 | ||
|
546c10020c | ||
|
46ff967f22 | ||
|
c11a7b4bb4 | ||
|
ed58d04879 | ||
|
742307e27e | ||
|
83e67d5b6f | ||
|
ea48be1db2 | ||
f0959a0dc0 | |||
|
5d2d924197 | ||
|
3926d55b62 | ||
|
6a3b3f5df8 | ||
|
f4e7d0dfd1 | ||
|
f2f0abdf47 | ||
006360cc2c | |||
|
e58de90d69 | ||
|
37751a173a | ||
|
d46ff8b1c1 | ||
|
01f3fceae8 | ||
|
d2f804af98 | ||
|
4ecfc8e06c | ||
|
0fe543624f | ||
|
7610ab8814 | ||
|
562498a420 | ||
|
44129fa1d3 | ||
|
04dc8b7cc6 | ||
|
a7cfd6d520 | ||
|
97166b27de | ||
49c02d50e1 | |||
|
f4a94a7bd5 | ||
|
8522c960cd | ||
|
f9be89e9c2 | ||
|
39f22a3b11 | ||
|
eff27d075b | ||
|
4c15718b7e | ||
|
d1edfddfae | ||
|
3b2aba6636 | ||
a3fa0ef215 | |||
|
d896f7d22d | ||
f76d25e3d0 | |||
|
258e186311 | ||
fc530c9f61 | |||
|
d64945a83f | ||
|
c48f71c99f | ||
|
58440d6d59 | ||
|
caf3e3826d | ||
|
d106aafb4f | ||
|
60f67a82fb | ||
|
17486e82ee | ||
|
f0134ead55 | ||
cb0bdb1166 | |||
|
bf9ed4a050 | ||
|
4f217f0ef7 | ||
|
3fcae28ac9 | ||
|
17c4173748 | ||
250e4f0bf3 | |||
|
c4a28ac4b1 | ||
|
effe4f1c13 | ||
|
01add1d430 | ||
|
29c87bfa11 | ||
|
25c5585f4b | ||
|
c107ee51ec | ||
|
b9b984a2cb | ||
|
7628cf9806 | ||
|
148c085271 | ||
|
75ef2258b1 | ||
|
297eb78784 | ||
|
18a4a19379 | ||
763dd31053 | |||
|
b8a97de4f9 | ||
|
503fe1452e | ||
|
834a6c13b2 | ||
|
65229ed8ca | ||
|
f28be49225 | ||
|
ca3dd6b390 | ||
|
1e9b2956e3 | ||
|
38874076d5 | ||
3432149a5d | |||
c682b9aa4b | |||
|
9b607f7f84 | ||
1f964c5f5c | |||
|
081e7784ed | ||
|
52869fbb8a | ||
|
c77b2a2d44 | ||
|
6fccb14e3e | ||
|
14431ee5e3 | ||
|
3996939f05 | ||
|
b29279ce1f | ||
|
45d83b2146 | ||
|
47c59641bc | ||
|
4c1534b0bb | ||
|
fdc8cb0be7 | ||
|
70d1fb0d8a | ||
|
cbfbca23e7 | ||
|
4c0baad5ee | ||
|
94504888ce | ||
|
232e4f1b06 | ||
|
d53ac62a71 | ||
|
70ec7b1da3 | ||
|
cb1c1660e9 | ||
|
d9678a010d | ||
|
ca3627b68b | ||
|
1d3ac33304 | ||
|
99ee939b47 | ||
|
e6e902cb40 | ||
|
eadd789ade | ||
|
af2fdffba5 | ||
|
2496371d0c | ||
|
5b62891dd0 | ||
|
f8762cb9a1 | ||
|
bccf18f0e9 | ||
|
99ddc9200a | ||
|
5b06e32564 | ||
|
cbebad1832 | ||
|
8217c87920 | ||
|
5ee927d2b0 | ||
|
80470c1977 | ||
|
d7d3a21179 | ||
|
0184389208 | ||
|
ed582c780e | ||
|
219a346c76 | ||
|
49544a06aa | ||
|
b49853cb60 | ||
|
c4aa50c45a | ||
|
3eeaaf1193 | ||
|
9b8893df8c | ||
|
a0bb62d71e | ||
|
0fec18559f | ||
|
2bbb120749 | ||
|
8bfe06f00e | ||
|
9c2104f0be | ||
|
7322b1ecec | ||
|
508cabcc0a | ||
|
7eab4ebfd6 | ||
|
846e88d38a | ||
|
89da41598e | ||
|
39daa0601d | ||
|
d9704970b2 | ||
|
93cfb71e48 | ||
|
a1a62483ca | ||
|
025bd09325 | ||
1d78ca1788 | |||
a22820054a | |||
|
e63f13b1cd | ||
|
c2311b77dc | ||
|
64d612e786 | ||
|
98118be39f | ||
4d06272ed2 | |||
|
70960b2961 | ||
d017be9aad | |||
|
f1c06aad3d | ||
|
5ced54d93a | ||
|
2025e64f36 | ||
|
37ee2873ae | ||
|
654284fdcb | ||
|
87ec61d0a9 | ||
|
09c4d230fb | ||
|
7e0a2b03a7 | ||
|
28d2bf6d34 | ||
|
c0ddccbcf7 | ||
|
4feca15c16 | ||
|
12501d95dc | ||
|
a45366dd54 | ||
|
007a8878bb | ||
|
ce99d98855 | ||
|
37ba719588 | ||
|
b084d1621f | ||
|
7cdf353caa | ||
|
e73315cf47 | ||
|
bc27c4a73d | ||
|
096d6fa788 | ||
|
5e3dbac6e5 | ||
|
19fa738f45 | ||
|
ffa9c51ffe | ||
|
d98ec15037 | ||
|
78c72de865 | ||
|
6cb8a11349 | ||
|
57b8c407a2 | ||
a28f918888 | |||
|
d027290d2a | ||
|
c219dd8a65 | ||
|
6ab5de6e62 | ||
|
999317dfcb | ||
|
06ab7f3ca1 | ||
|
788d79cc5e | ||
|
9261f41d52 | ||
|
2b6ca23944 | ||
5047a183aa | |||
5fddbbecb1 | |||
|
df0d110a10 | ||
|
4c1c115881 | ||
|
258ec13a55 | ||
|
4cbb1ca056 | ||
|
97844ea57b | ||
|
cb19fb1dc5 | ||
|
d571239fa3 | ||
|
dd5f8efa92 | ||
|
b3a8ed77d1 | ||
|
30f5837aed | ||
|
db137498e6 | ||
|
fb1f93b19c | ||
|
9968fdc9c4 | ||
|
67919e156c | ||
|
609ffeb1bf | ||
|
91a4e0a8ca | ||
|
9179fa29b0 | ||
dfb18c1dd8 | |||
|
c7df9aa9df | ||
|
d9ffae2bfe | ||
|
41e2e37524 | ||
99e20663a7 | |||
d5d00e849b | |||
|
9c89d4e922 | ||
|
588643e5dd | ||
|
dd8f816344 | ||
ba2da53540 | |||
|
da048ebb2c | ||
|
5a02daea40 | ||
3ccb789bdd | |||
|
65afd4a6e5 | ||
|
d92d715ee4 | ||
|
b108ff9157 | ||
|
338c6ff85f | ||
|
29fc15b2c5 | ||
|
f15b8fee1d | ||
|
bcb31a8815 | ||
|
fa45dcdd2c | ||
|
31682f76fd | ||
|
ec4335c517 | ||
e4fef71442 | |||
4dc5bb1bd8 | |||
|
a2f7422591 | ||
|
b820f4646a | ||
264976c2e4 | |||
|
ba10c5467c | ||
|
004942048d | ||
5963668dfa | |||
c6b63909d0 | |||
2ab1ad34e0 | |||
0ceb550fae | |||
|
b5d362417d | ||
7f2dc5a612 | |||
895a1f07ce | |||
|
91db402d3b |
|
@ -1,23 +0,0 @@
|
||||||
# Changelog
|
|
||||||
|
|
||||||
{{ range .Versions -}}
|
|
||||||
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})
|
|
||||||
|
|
||||||
{{ range .CommitGroups -}}
|
|
||||||
### {{ .Title }}
|
|
||||||
|
|
||||||
{{ range .Commits -}}
|
|
||||||
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ (regexReplaceAll "(.*)/issues/(.*)" (regexReplaceAll "(Co-\\w*-by.*)" .Subject "") "${1}/pull/${2}") | trim }}
|
|
||||||
{{ end }}
|
|
||||||
{{- end -}}
|
|
||||||
|
|
||||||
{{- if .NoteGroups -}}
|
|
||||||
{{ range .NoteGroups -}}
|
|
||||||
### {{ .Title }}
|
|
||||||
|
|
||||||
{{ range .Notes }}
|
|
||||||
{{ .Body }}
|
|
||||||
{{ end }}
|
|
||||||
{{ end -}}
|
|
||||||
{{ end -}}
|
|
||||||
{{ end -}}
|
|
|
@ -1,25 +0,0 @@
|
||||||
style: github
|
|
||||||
template: CHANGELOG.tpl.md
|
|
||||||
info:
|
|
||||||
title: CHANGELOG
|
|
||||||
repository_url: https://github.com/thegeeklab/prometheus-pve-sd
|
|
||||||
options:
|
|
||||||
commit_groups:
|
|
||||||
title_maps:
|
|
||||||
feat: Features
|
|
||||||
fix: Bug Fixes
|
|
||||||
perf: Performance Improvements
|
|
||||||
refactor: Code Refactoring
|
|
||||||
chore: Others
|
|
||||||
test: Testing
|
|
||||||
ci: CI Pipeline
|
|
||||||
docs: Documentation
|
|
||||||
header:
|
|
||||||
pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
|
|
||||||
pattern_maps:
|
|
||||||
- Type
|
|
||||||
- Scope
|
|
||||||
- Subject
|
|
||||||
notes:
|
|
||||||
keywords:
|
|
||||||
- BREAKING CHANGE
|
|
12
.dictionary
12
.dictionary
|
@ -10,3 +10,15 @@ SELinux
|
||||||
CLI
|
CLI
|
||||||
JSON
|
JSON
|
||||||
toc
|
toc
|
||||||
|
Codecov
|
||||||
|
IPv4
|
||||||
|
IPv6
|
||||||
|
Alertmanager
|
||||||
|
VM
|
||||||
|
VMID
|
||||||
|
Telegraf
|
||||||
|
QEMU
|
||||||
|
cloud-init
|
||||||
|
Prometheus
|
||||||
|
Kubernetes
|
||||||
|
namespace
|
||||||
|
|
512
.drone.jsonnet
512
.drone.jsonnet
|
@ -1,512 +0,0 @@
|
||||||
local PythonVersion(pyversion='3.7') = {
|
|
||||||
name: 'python' + std.strReplace(pyversion, '.', '') + '-pytest',
|
|
||||||
image: 'python:' + pyversion,
|
|
||||||
environment: {
|
|
||||||
PY_COLORS: 1,
|
|
||||||
},
|
|
||||||
commands: [
|
|
||||||
'pip install poetry poetry-dynamic-versioning -qq',
|
|
||||||
'poetry config experimental.new-installer false',
|
|
||||||
'poetry install',
|
|
||||||
'poetry run pytest',
|
|
||||||
'poetry version',
|
|
||||||
'poetry run prometheus-pve-sd --help',
|
|
||||||
],
|
|
||||||
depends_on: [
|
|
||||||
'fetch',
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
local PipelineLint = {
|
|
||||||
kind: 'pipeline',
|
|
||||||
name: 'lint',
|
|
||||||
platform: {
|
|
||||||
os: 'linux',
|
|
||||||
arch: 'amd64',
|
|
||||||
},
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
name: 'yapf',
|
|
||||||
image: 'python:3.10',
|
|
||||||
environment: {
|
|
||||||
PY_COLORS: 1,
|
|
||||||
},
|
|
||||||
commands: [
|
|
||||||
'git fetch -tq',
|
|
||||||
'pip install poetry poetry-dynamic-versioning -qq',
|
|
||||||
'poetry config experimental.new-installer false',
|
|
||||||
'poetry install',
|
|
||||||
'poetry run yapf -dr ./prometheuspvesd',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'flake8',
|
|
||||||
image: 'python:3.10',
|
|
||||||
environment: {
|
|
||||||
PY_COLORS: 1,
|
|
||||||
},
|
|
||||||
commands: [
|
|
||||||
'git fetch -tq',
|
|
||||||
'pip install poetry poetry-dynamic-versioning -qq',
|
|
||||||
'poetry config experimental.new-installer false',
|
|
||||||
'poetry install',
|
|
||||||
'poetry run flake8 ./prometheuspvesd',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
trigger: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
local PipelineTest = {
|
|
||||||
kind: 'pipeline',
|
|
||||||
name: 'test',
|
|
||||||
platform: {
|
|
||||||
os: 'linux',
|
|
||||||
arch: 'amd64',
|
|
||||||
},
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
name: 'fetch',
|
|
||||||
image: 'python:3.10',
|
|
||||||
commands: [
|
|
||||||
'git fetch -tq',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
PythonVersion(pyversion='3.7'),
|
|
||||||
PythonVersion(pyversion='3.8'),
|
|
||||||
PythonVersion(pyversion='3.9'),
|
|
||||||
PythonVersion(pyversion='3.10'),
|
|
||||||
{
|
|
||||||
name: 'codecov',
|
|
||||||
image: 'python:3.10',
|
|
||||||
environment: {
|
|
||||||
PY_COLORS: 1,
|
|
||||||
CODECOV_TOKEN: { from_secret: 'codecov_token' },
|
|
||||||
},
|
|
||||||
commands: [
|
|
||||||
'pip install codecov -qq',
|
|
||||||
'codecov --required -X gcov',
|
|
||||||
],
|
|
||||||
depends_on: [
|
|
||||||
'python37-pytest',
|
|
||||||
'python38-pytest',
|
|
||||||
'python39-pytest',
|
|
||||||
'python310-pytest',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
depends_on: [
|
|
||||||
'lint',
|
|
||||||
],
|
|
||||||
trigger: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
local PipelineSecurity = {
|
|
||||||
kind: 'pipeline',
|
|
||||||
name: 'security',
|
|
||||||
platform: {
|
|
||||||
os: 'linux',
|
|
||||||
arch: 'amd64',
|
|
||||||
},
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
name: 'bandit',
|
|
||||||
image: 'python:3.10',
|
|
||||||
environment: {
|
|
||||||
PY_COLORS: 1,
|
|
||||||
},
|
|
||||||
commands: [
|
|
||||||
'git fetch -tq',
|
|
||||||
'pip install poetry poetry-dynamic-versioning -qq',
|
|
||||||
'poetry config experimental.new-installer false',
|
|
||||||
'poetry install',
|
|
||||||
'poetry run bandit -r ./prometheuspvesd -x ./prometheuspvesd/test',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
depends_on: [
|
|
||||||
'test',
|
|
||||||
],
|
|
||||||
trigger: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
local PipelineBuildPackage = {
|
|
||||||
kind: 'pipeline',
|
|
||||||
name: 'build-package',
|
|
||||||
platform: {
|
|
||||||
os: 'linux',
|
|
||||||
arch: 'amd64',
|
|
||||||
},
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
name: 'build',
|
|
||||||
image: 'python:3.10',
|
|
||||||
commands: [
|
|
||||||
'git fetch -tq',
|
|
||||||
'pip install poetry poetry-dynamic-versioning -qq',
|
|
||||||
'poetry build',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'checksum',
|
|
||||||
image: 'alpine',
|
|
||||||
commands: [
|
|
||||||
'cd dist/ && sha256sum * > ../sha256sum.txt',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'changelog-generate',
|
|
||||||
image: 'thegeeklab/git-chglog',
|
|
||||||
commands: [
|
|
||||||
'git fetch -tq',
|
|
||||||
'git-chglog --no-color --no-emoji -o CHANGELOG.md ${DRONE_TAG:---next-tag unreleased unreleased}',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'changelog-format',
|
|
||||||
image: 'thegeeklab/alpine-tools',
|
|
||||||
commands: [
|
|
||||||
'prettier CHANGELOG.md',
|
|
||||||
'prettier -w CHANGELOG.md',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'publish-github',
|
|
||||||
image: 'plugins/github-release',
|
|
||||||
settings: {
|
|
||||||
overwrite: true,
|
|
||||||
api_key: { from_secret: 'github_token' },
|
|
||||||
files: ['dist/*', 'sha256sum.txt'],
|
|
||||||
title: '${DRONE_TAG}',
|
|
||||||
note: 'CHANGELOG.md',
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
ref: ['refs/tags/**'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'publish-pypi',
|
|
||||||
image: 'python:3.10',
|
|
||||||
commands: [
|
|
||||||
'git fetch -tq',
|
|
||||||
'pip install poetry poetry-dynamic-versioning -qq',
|
|
||||||
'poetry publish -n',
|
|
||||||
],
|
|
||||||
environment: {
|
|
||||||
POETRY_HTTP_BASIC_PYPI_USERNAME: { from_secret: 'pypi_username' },
|
|
||||||
POETRY_HTTP_BASIC_PYPI_PASSWORD: { from_secret: 'pypi_password' },
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
ref: ['refs/tags/**'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
depends_on: [
|
|
||||||
'security',
|
|
||||||
],
|
|
||||||
trigger: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
local PipelineBuildContainer(arch='amd64') = {
|
|
||||||
local build = if arch == 'arm' then [{
|
|
||||||
name: 'build',
|
|
||||||
image: 'python:3.10-alpine',
|
|
||||||
commands: [
|
|
||||||
'apk add -Uq --no-cache build-base openssl-dev libffi-dev musl-dev python3-dev git cargo',
|
|
||||||
'git fetch -tq',
|
|
||||||
'pip install poetry poetry-dynamic-versioning -qq',
|
|
||||||
'poetry build',
|
|
||||||
],
|
|
||||||
environment: {
|
|
||||||
CARGO_NET_GIT_FETCH_WITH_CLI: true,
|
|
||||||
},
|
|
||||||
}] else [{
|
|
||||||
name: 'build',
|
|
||||||
image: 'python:3.10',
|
|
||||||
commands: [
|
|
||||||
'git fetch -tq',
|
|
||||||
'pip install poetry poetry-dynamic-versioning -qq',
|
|
||||||
'poetry build',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
|
|
||||||
kind: 'pipeline',
|
|
||||||
name: 'build-container-' + arch,
|
|
||||||
platform: {
|
|
||||||
os: 'linux',
|
|
||||||
arch: arch,
|
|
||||||
},
|
|
||||||
steps: build + [
|
|
||||||
{
|
|
||||||
name: 'dryrun',
|
|
||||||
image: 'thegeeklab/drone-docker:19',
|
|
||||||
settings: {
|
|
||||||
dry_run: true,
|
|
||||||
dockerfile: 'docker/Dockerfile.' + arch,
|
|
||||||
repo: 'thegeeklab/${DRONE_REPO_NAME}',
|
|
||||||
username: { from_secret: 'docker_username' },
|
|
||||||
password: { from_secret: 'docker_password' },
|
|
||||||
},
|
|
||||||
depends_on: ['build'],
|
|
||||||
when: {
|
|
||||||
ref: ['refs/pull/**'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'publish-dockerhub',
|
|
||||||
image: 'thegeeklab/drone-docker:19',
|
|
||||||
settings: {
|
|
||||||
auto_tag: true,
|
|
||||||
auto_tag_suffix: arch,
|
|
||||||
dockerfile: 'docker/Dockerfile.' + arch,
|
|
||||||
repo: 'thegeeklab/${DRONE_REPO_NAME}',
|
|
||||||
username: { from_secret: 'docker_username' },
|
|
||||||
password: { from_secret: 'docker_password' },
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**'],
|
|
||||||
},
|
|
||||||
depends_on: ['dryrun'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'publish-quay',
|
|
||||||
image: 'thegeeklab/drone-docker:19',
|
|
||||||
settings: {
|
|
||||||
auto_tag: true,
|
|
||||||
auto_tag_suffix: arch,
|
|
||||||
dockerfile: 'docker/Dockerfile.' + arch,
|
|
||||||
registry: 'quay.io',
|
|
||||||
repo: 'quay.io/thegeeklab/${DRONE_REPO_NAME}',
|
|
||||||
username: { from_secret: 'quay_username' },
|
|
||||||
password: { from_secret: 'quay_password' },
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**'],
|
|
||||||
},
|
|
||||||
depends_on: ['dryrun'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
depends_on: [
|
|
||||||
'security',
|
|
||||||
],
|
|
||||||
trigger: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
local PipelineDocs = {
|
|
||||||
kind: 'pipeline',
|
|
||||||
name: 'docs',
|
|
||||||
platform: {
|
|
||||||
os: 'linux',
|
|
||||||
arch: 'amd64',
|
|
||||||
},
|
|
||||||
concurrency: {
|
|
||||||
limit: 1,
|
|
||||||
},
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
name: 'assets',
|
|
||||||
image: 'thegeeklab/alpine-tools',
|
|
||||||
commands: [
|
|
||||||
'make doc',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'markdownlint',
|
|
||||||
image: 'thegeeklab/markdownlint-cli',
|
|
||||||
commands: [
|
|
||||||
"markdownlint 'docs/content/**/*.md' 'README.md' 'CONTRIBUTING.md'",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'spellcheck',
|
|
||||||
image: 'node:lts-alpine',
|
|
||||||
commands: [
|
|
||||||
'npm install -g spellchecker-cli',
|
|
||||||
"spellchecker --files 'docs/content/**/*.md' 'README.md' -d .dictionary -p spell indefinite-article syntax-urls --no-suggestions",
|
|
||||||
],
|
|
||||||
environment: {
|
|
||||||
FORCE_COLOR: true,
|
|
||||||
NPM_CONFIG_LOGLEVEL: 'error',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'testbuild',
|
|
||||||
image: 'thegeeklab/hugo:0.91.0',
|
|
||||||
commands: [
|
|
||||||
'hugo -s docs/ -b http://localhost/',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'link-validation',
|
|
||||||
image: 'thegeeklab/link-validator',
|
|
||||||
commands: [
|
|
||||||
'link-validator -ro',
|
|
||||||
],
|
|
||||||
environment: {
|
|
||||||
LINK_VALIDATOR_BASE_DIR: 'docs/public',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'build',
|
|
||||||
image: 'thegeeklab/hugo:0.91.0',
|
|
||||||
commands: [
|
|
||||||
'hugo -s docs/',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'beautify',
|
|
||||||
image: 'node:lts-alpine',
|
|
||||||
commands: [
|
|
||||||
'npm install -g js-beautify',
|
|
||||||
"html-beautify -r -f 'docs/public/**/*.html'",
|
|
||||||
],
|
|
||||||
environment: {
|
|
||||||
FORCE_COLOR: true,
|
|
||||||
NPM_CONFIG_LOGLEVEL: 'error',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'publish',
|
|
||||||
image: 'plugins/s3-sync',
|
|
||||||
settings: {
|
|
||||||
access_key: { from_secret: 's3_access_key' },
|
|
||||||
bucket: 'geekdocs',
|
|
||||||
delete: true,
|
|
||||||
endpoint: 'https://sp.rknet.org',
|
|
||||||
path_style: true,
|
|
||||||
secret_key: { from_secret: 's3_secret_access_key' },
|
|
||||||
source: 'docs/public/',
|
|
||||||
strip_prefix: 'docs/public/',
|
|
||||||
target: '/${DRONE_REPO_NAME}',
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
depends_on: [
|
|
||||||
'build-package',
|
|
||||||
'build-container-amd64',
|
|
||||||
'build-container-arm64',
|
|
||||||
'build-container-arm',
|
|
||||||
],
|
|
||||||
trigger: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
local PipelineNotifications = {
|
|
||||||
kind: 'pipeline',
|
|
||||||
name: 'notifications',
|
|
||||||
platform: {
|
|
||||||
os: 'linux',
|
|
||||||
arch: 'amd64',
|
|
||||||
},
|
|
||||||
steps: [
|
|
||||||
{
|
|
||||||
image: 'plugins/manifest',
|
|
||||||
name: 'manifest-dockerhub',
|
|
||||||
settings: {
|
|
||||||
ignore_missing: true,
|
|
||||||
auto_tag: true,
|
|
||||||
username: { from_secret: 'docker_username' },
|
|
||||||
password: { from_secret: 'docker_password' },
|
|
||||||
spec: 'docker/manifest.tmpl',
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
status: ['success'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
image: 'plugins/manifest',
|
|
||||||
name: 'manifest-quay',
|
|
||||||
settings: {
|
|
||||||
ignore_missing: true,
|
|
||||||
auto_tag: true,
|
|
||||||
username: { from_secret: 'quay_username' },
|
|
||||||
password: { from_secret: 'quay_password' },
|
|
||||||
spec: 'docker/manifest-quay.tmpl',
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
status: ['success'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'pushrm-dockerhub',
|
|
||||||
pull: 'always',
|
|
||||||
image: 'chko/docker-pushrm:1',
|
|
||||||
environment: {
|
|
||||||
DOCKER_PASS: {
|
|
||||||
from_secret: 'docker_password',
|
|
||||||
},
|
|
||||||
DOCKER_USER: {
|
|
||||||
from_secret: 'docker_username',
|
|
||||||
},
|
|
||||||
PUSHRM_FILE: 'README.md',
|
|
||||||
PUSHRM_SHORT: 'Prometheus Service Discovery for Proxmox VE',
|
|
||||||
PUSHRM_TARGET: 'thegeeklab/${DRONE_REPO_NAME}',
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
status: ['success'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'pushrm-quay',
|
|
||||||
pull: 'always',
|
|
||||||
image: 'chko/docker-pushrm:1',
|
|
||||||
environment: {
|
|
||||||
APIKEY__QUAY_IO: {
|
|
||||||
from_secret: 'quay_token',
|
|
||||||
},
|
|
||||||
PUSHRM_FILE: 'README.md',
|
|
||||||
PUSHRM_TARGET: 'quay.io/thegeeklab/${DRONE_REPO_NAME}',
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
status: ['success'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'matrix',
|
|
||||||
image: 'thegeeklab/drone-matrix',
|
|
||||||
settings: {
|
|
||||||
homeserver: { from_secret: 'matrix_homeserver' },
|
|
||||||
roomid: { from_secret: 'matrix_roomid' },
|
|
||||||
template: 'Status: **{{ build.Status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.Link }}){{#if build.Branch}} ({{ build.Branch }}){{/if}} by {{ commit.Author }}<br/> Message: {{ commit.Message.Title }}',
|
|
||||||
username: { from_secret: 'matrix_username' },
|
|
||||||
password: { from_secret: 'matrix_password' },
|
|
||||||
},
|
|
||||||
when: {
|
|
||||||
status: ['success', 'failure'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
depends_on: [
|
|
||||||
'docs',
|
|
||||||
],
|
|
||||||
trigger: {
|
|
||||||
ref: ['refs/heads/main', 'refs/tags/**'],
|
|
||||||
status: ['success', 'failure'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
[
|
|
||||||
PipelineLint,
|
|
||||||
PipelineTest,
|
|
||||||
PipelineSecurity,
|
|
||||||
PipelineBuildPackage,
|
|
||||||
PipelineBuildContainer(arch='amd64'),
|
|
||||||
PipelineBuildContainer(arch='arm64'),
|
|
||||||
PipelineBuildContainer(arch='arm'),
|
|
||||||
PipelineDocs,
|
|
||||||
PipelineNotifications,
|
|
||||||
]
|
|
654
.drone.yml
654
.drone.yml
|
@ -1,654 +0,0 @@
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: lint
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: yapf
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- git fetch -tq
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry config experimental.new-installer false
|
|
||||||
- poetry install
|
|
||||||
- poetry run yapf -dr ./prometheuspvesd
|
|
||||||
environment:
|
|
||||||
PY_COLORS: 1
|
|
||||||
|
|
||||||
- name: flake8
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- git fetch -tq
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry config experimental.new-installer false
|
|
||||||
- poetry install
|
|
||||||
- poetry run flake8 ./prometheuspvesd
|
|
||||||
environment:
|
|
||||||
PY_COLORS: 1
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: test
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: fetch
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- git fetch -tq
|
|
||||||
|
|
||||||
- name: python37-pytest
|
|
||||||
image: python:3.7
|
|
||||||
commands:
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry config experimental.new-installer false
|
|
||||||
- poetry install
|
|
||||||
- poetry run pytest
|
|
||||||
- poetry version
|
|
||||||
- poetry run prometheus-pve-sd --help
|
|
||||||
environment:
|
|
||||||
PY_COLORS: 1
|
|
||||||
depends_on:
|
|
||||||
- fetch
|
|
||||||
|
|
||||||
- name: python38-pytest
|
|
||||||
image: python:3.8
|
|
||||||
commands:
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry config experimental.new-installer false
|
|
||||||
- poetry install
|
|
||||||
- poetry run pytest
|
|
||||||
- poetry version
|
|
||||||
- poetry run prometheus-pve-sd --help
|
|
||||||
environment:
|
|
||||||
PY_COLORS: 1
|
|
||||||
depends_on:
|
|
||||||
- fetch
|
|
||||||
|
|
||||||
- name: python39-pytest
|
|
||||||
image: python:3.9
|
|
||||||
commands:
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry config experimental.new-installer false
|
|
||||||
- poetry install
|
|
||||||
- poetry run pytest
|
|
||||||
- poetry version
|
|
||||||
- poetry run prometheus-pve-sd --help
|
|
||||||
environment:
|
|
||||||
PY_COLORS: 1
|
|
||||||
depends_on:
|
|
||||||
- fetch
|
|
||||||
|
|
||||||
- name: python310-pytest
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry config experimental.new-installer false
|
|
||||||
- poetry install
|
|
||||||
- poetry run pytest
|
|
||||||
- poetry version
|
|
||||||
- poetry run prometheus-pve-sd --help
|
|
||||||
environment:
|
|
||||||
PY_COLORS: 1
|
|
||||||
depends_on:
|
|
||||||
- fetch
|
|
||||||
|
|
||||||
- name: codecov
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- pip install codecov -qq
|
|
||||||
- codecov --required -X gcov
|
|
||||||
environment:
|
|
||||||
CODECOV_TOKEN:
|
|
||||||
from_secret: codecov_token
|
|
||||||
PY_COLORS: 1
|
|
||||||
depends_on:
|
|
||||||
- python37-pytest
|
|
||||||
- python38-pytest
|
|
||||||
- python39-pytest
|
|
||||||
- python310-pytest
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- lint
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: security
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: bandit
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- git fetch -tq
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry config experimental.new-installer false
|
|
||||||
- poetry install
|
|
||||||
- poetry run bandit -r ./prometheuspvesd -x ./prometheuspvesd/test
|
|
||||||
environment:
|
|
||||||
PY_COLORS: 1
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- test
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: build-package
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: build
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- git fetch -tq
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry build
|
|
||||||
|
|
||||||
- name: checksum
|
|
||||||
image: alpine
|
|
||||||
commands:
|
|
||||||
- cd dist/ && sha256sum * > ../sha256sum.txt
|
|
||||||
|
|
||||||
- name: changelog-generate
|
|
||||||
image: thegeeklab/git-chglog
|
|
||||||
commands:
|
|
||||||
- git fetch -tq
|
|
||||||
- git-chglog --no-color --no-emoji -o CHANGELOG.md ${DRONE_TAG:---next-tag unreleased unreleased}
|
|
||||||
|
|
||||||
- name: changelog-format
|
|
||||||
image: thegeeklab/alpine-tools
|
|
||||||
commands:
|
|
||||||
- prettier CHANGELOG.md
|
|
||||||
- prettier -w CHANGELOG.md
|
|
||||||
|
|
||||||
- name: publish-github
|
|
||||||
image: plugins/github-release
|
|
||||||
settings:
|
|
||||||
api_key:
|
|
||||||
from_secret: github_token
|
|
||||||
files:
|
|
||||||
- dist/*
|
|
||||||
- sha256sum.txt
|
|
||||||
note: CHANGELOG.md
|
|
||||||
overwrite: true
|
|
||||||
title: ${DRONE_TAG}
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/tags/**
|
|
||||||
|
|
||||||
- name: publish-pypi
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- git fetch -tq
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry publish -n
|
|
||||||
environment:
|
|
||||||
POETRY_HTTP_BASIC_PYPI_PASSWORD:
|
|
||||||
from_secret: pypi_password
|
|
||||||
POETRY_HTTP_BASIC_PYPI_USERNAME:
|
|
||||||
from_secret: pypi_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/tags/**
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- security
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: build-container-amd64
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: build
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- git fetch -tq
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry build
|
|
||||||
|
|
||||||
- name: dryrun
|
|
||||||
image: thegeeklab/drone-docker:19
|
|
||||||
settings:
|
|
||||||
dockerfile: docker/Dockerfile.amd64
|
|
||||||
dry_run: true
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
repo: thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/pull/**
|
|
||||||
depends_on:
|
|
||||||
- build
|
|
||||||
|
|
||||||
- name: publish-dockerhub
|
|
||||||
image: thegeeklab/drone-docker:19
|
|
||||||
settings:
|
|
||||||
auto_tag: true
|
|
||||||
auto_tag_suffix: amd64
|
|
||||||
dockerfile: docker/Dockerfile.amd64
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
repo: thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
depends_on:
|
|
||||||
- dryrun
|
|
||||||
|
|
||||||
- name: publish-quay
|
|
||||||
image: thegeeklab/drone-docker:19
|
|
||||||
settings:
|
|
||||||
auto_tag: true
|
|
||||||
auto_tag_suffix: amd64
|
|
||||||
dockerfile: docker/Dockerfile.amd64
|
|
||||||
password:
|
|
||||||
from_secret: quay_password
|
|
||||||
registry: quay.io
|
|
||||||
repo: quay.io/thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: quay_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
depends_on:
|
|
||||||
- dryrun
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- security
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: build-container-arm64
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: arm64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: build
|
|
||||||
image: python:3.10
|
|
||||||
commands:
|
|
||||||
- git fetch -tq
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry build
|
|
||||||
|
|
||||||
- name: dryrun
|
|
||||||
image: thegeeklab/drone-docker:19
|
|
||||||
settings:
|
|
||||||
dockerfile: docker/Dockerfile.arm64
|
|
||||||
dry_run: true
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
repo: thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/pull/**
|
|
||||||
depends_on:
|
|
||||||
- build
|
|
||||||
|
|
||||||
- name: publish-dockerhub
|
|
||||||
image: thegeeklab/drone-docker:19
|
|
||||||
settings:
|
|
||||||
auto_tag: true
|
|
||||||
auto_tag_suffix: arm64
|
|
||||||
dockerfile: docker/Dockerfile.arm64
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
repo: thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
depends_on:
|
|
||||||
- dryrun
|
|
||||||
|
|
||||||
- name: publish-quay
|
|
||||||
image: thegeeklab/drone-docker:19
|
|
||||||
settings:
|
|
||||||
auto_tag: true
|
|
||||||
auto_tag_suffix: arm64
|
|
||||||
dockerfile: docker/Dockerfile.arm64
|
|
||||||
password:
|
|
||||||
from_secret: quay_password
|
|
||||||
registry: quay.io
|
|
||||||
repo: quay.io/thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: quay_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
depends_on:
|
|
||||||
- dryrun
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- security
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: build-container-arm
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: arm
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: build
|
|
||||||
image: python:3.10-alpine
|
|
||||||
commands:
|
|
||||||
- apk add -Uq --no-cache build-base openssl-dev libffi-dev musl-dev python3-dev git cargo
|
|
||||||
- git fetch -tq
|
|
||||||
- pip install poetry poetry-dynamic-versioning -qq
|
|
||||||
- poetry build
|
|
||||||
environment:
|
|
||||||
CARGO_NET_GIT_FETCH_WITH_CLI: true
|
|
||||||
|
|
||||||
- name: dryrun
|
|
||||||
image: thegeeklab/drone-docker:19
|
|
||||||
settings:
|
|
||||||
dockerfile: docker/Dockerfile.arm
|
|
||||||
dry_run: true
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
repo: thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/pull/**
|
|
||||||
depends_on:
|
|
||||||
- build
|
|
||||||
|
|
||||||
- name: publish-dockerhub
|
|
||||||
image: thegeeklab/drone-docker:19
|
|
||||||
settings:
|
|
||||||
auto_tag: true
|
|
||||||
auto_tag_suffix: arm
|
|
||||||
dockerfile: docker/Dockerfile.arm
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
repo: thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
depends_on:
|
|
||||||
- dryrun
|
|
||||||
|
|
||||||
- name: publish-quay
|
|
||||||
image: thegeeklab/drone-docker:19
|
|
||||||
settings:
|
|
||||||
auto_tag: true
|
|
||||||
auto_tag_suffix: arm
|
|
||||||
dockerfile: docker/Dockerfile.arm
|
|
||||||
password:
|
|
||||||
from_secret: quay_password
|
|
||||||
registry: quay.io
|
|
||||||
repo: quay.io/thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: quay_username
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
depends_on:
|
|
||||||
- dryrun
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- security
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: docs
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
limit: 1
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: assets
|
|
||||||
image: thegeeklab/alpine-tools
|
|
||||||
commands:
|
|
||||||
- make doc
|
|
||||||
|
|
||||||
- name: markdownlint
|
|
||||||
image: thegeeklab/markdownlint-cli
|
|
||||||
commands:
|
|
||||||
- markdownlint 'docs/content/**/*.md' 'README.md' 'CONTRIBUTING.md'
|
|
||||||
|
|
||||||
- name: spellcheck
|
|
||||||
image: node:lts-alpine
|
|
||||||
commands:
|
|
||||||
- npm install -g spellchecker-cli
|
|
||||||
- spellchecker --files 'docs/content/**/*.md' 'README.md' -d .dictionary -p spell indefinite-article syntax-urls --no-suggestions
|
|
||||||
environment:
|
|
||||||
FORCE_COLOR: true
|
|
||||||
NPM_CONFIG_LOGLEVEL: error
|
|
||||||
|
|
||||||
- name: testbuild
|
|
||||||
image: thegeeklab/hugo:0.91.0
|
|
||||||
commands:
|
|
||||||
- hugo -s docs/ -b http://localhost/
|
|
||||||
|
|
||||||
- name: link-validation
|
|
||||||
image: thegeeklab/link-validator
|
|
||||||
commands:
|
|
||||||
- link-validator -ro
|
|
||||||
environment:
|
|
||||||
LINK_VALIDATOR_BASE_DIR: docs/public
|
|
||||||
|
|
||||||
- name: build
|
|
||||||
image: thegeeklab/hugo:0.91.0
|
|
||||||
commands:
|
|
||||||
- hugo -s docs/
|
|
||||||
|
|
||||||
- name: beautify
|
|
||||||
image: node:lts-alpine
|
|
||||||
commands:
|
|
||||||
- npm install -g js-beautify
|
|
||||||
- html-beautify -r -f 'docs/public/**/*.html'
|
|
||||||
environment:
|
|
||||||
FORCE_COLOR: true
|
|
||||||
NPM_CONFIG_LOGLEVEL: error
|
|
||||||
|
|
||||||
- name: publish
|
|
||||||
image: plugins/s3-sync
|
|
||||||
settings:
|
|
||||||
access_key:
|
|
||||||
from_secret: s3_access_key
|
|
||||||
bucket: geekdocs
|
|
||||||
delete: true
|
|
||||||
endpoint: https://sp.rknet.org
|
|
||||||
path_style: true
|
|
||||||
secret_key:
|
|
||||||
from_secret: s3_secret_access_key
|
|
||||||
source: docs/public/
|
|
||||||
strip_prefix: docs/public/
|
|
||||||
target: /${DRONE_REPO_NAME}
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
- refs/pull/**
|
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- build-package
|
|
||||||
- build-container-amd64
|
|
||||||
- build-container-arm64
|
|
||||||
- build-container-arm
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: notifications
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: manifest-dockerhub
|
|
||||||
image: plugins/manifest
|
|
||||||
settings:
|
|
||||||
auto_tag: true
|
|
||||||
ignore_missing: true
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
spec: docker/manifest.tmpl
|
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
when:
|
|
||||||
status:
|
|
||||||
- success
|
|
||||||
|
|
||||||
- name: manifest-quay
|
|
||||||
image: plugins/manifest
|
|
||||||
settings:
|
|
||||||
auto_tag: true
|
|
||||||
ignore_missing: true
|
|
||||||
password:
|
|
||||||
from_secret: quay_password
|
|
||||||
spec: docker/manifest-quay.tmpl
|
|
||||||
username:
|
|
||||||
from_secret: quay_username
|
|
||||||
when:
|
|
||||||
status:
|
|
||||||
- success
|
|
||||||
|
|
||||||
- name: pushrm-dockerhub
|
|
||||||
pull: always
|
|
||||||
image: chko/docker-pushrm:1
|
|
||||||
environment:
|
|
||||||
DOCKER_PASS:
|
|
||||||
from_secret: docker_password
|
|
||||||
DOCKER_USER:
|
|
||||||
from_secret: docker_username
|
|
||||||
PUSHRM_FILE: README.md
|
|
||||||
PUSHRM_SHORT: Prometheus Service Discovery for Proxmox VE
|
|
||||||
PUSHRM_TARGET: thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
when:
|
|
||||||
status:
|
|
||||||
- success
|
|
||||||
|
|
||||||
- name: pushrm-quay
|
|
||||||
pull: always
|
|
||||||
image: chko/docker-pushrm:1
|
|
||||||
environment:
|
|
||||||
APIKEY__QUAY_IO:
|
|
||||||
from_secret: quay_token
|
|
||||||
PUSHRM_FILE: README.md
|
|
||||||
PUSHRM_TARGET: quay.io/thegeeklab/${DRONE_REPO_NAME}
|
|
||||||
when:
|
|
||||||
status:
|
|
||||||
- success
|
|
||||||
|
|
||||||
- name: matrix
|
|
||||||
image: thegeeklab/drone-matrix
|
|
||||||
settings:
|
|
||||||
homeserver:
|
|
||||||
from_secret: matrix_homeserver
|
|
||||||
password:
|
|
||||||
from_secret: matrix_password
|
|
||||||
roomid:
|
|
||||||
from_secret: matrix_roomid
|
|
||||||
template: "Status: **{{ build.Status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.Link }}){{#if build.Branch}} ({{ build.Branch }}){{/if}} by {{ commit.Author }}<br/> Message: {{ commit.Message.Title }}"
|
|
||||||
username:
|
|
||||||
from_secret: matrix_username
|
|
||||||
when:
|
|
||||||
status:
|
|
||||||
- success
|
|
||||||
- failure
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
ref:
|
|
||||||
- refs/heads/main
|
|
||||||
- refs/tags/**
|
|
||||||
status:
|
|
||||||
- success
|
|
||||||
- failure
|
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- docs
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: signature
|
|
||||||
hmac: e86573972517f4268f7a372b00261aae9924e4f1c014153f00391bb231271bd5
|
|
||||||
|
|
||||||
...
|
|
9
.github/settings.yml
vendored
9
.github/settings.yml
vendored
|
@ -52,6 +52,11 @@ branches:
|
||||||
required_status_checks:
|
required_status_checks:
|
||||||
strict: false
|
strict: false
|
||||||
contexts:
|
contexts:
|
||||||
- continuous-integration/drone/pr
|
- ci/woodpecker/pr/lint
|
||||||
enforce_admins: null
|
- ci/woodpecker/pr/test
|
||||||
|
- ci/woodpecker/pr/build-package
|
||||||
|
- ci/woodpecker/pr/build-container
|
||||||
|
- ci/woodpecker/pr/docs
|
||||||
|
enforce_admins: false
|
||||||
|
required_linear_history: true
|
||||||
restrictions: null
|
restrictions: null
|
||||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -106,6 +106,8 @@ pip-wheel-metadata
|
||||||
docs/themes/
|
docs/themes/
|
||||||
docs/public/
|
docs/public/
|
||||||
resources/_gen/
|
resources/_gen/
|
||||||
|
.hugo_build.lock
|
||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
|
.ruff_cache
|
||||||
|
|
47
.gitsv/config.yml
Normal file
47
.gitsv/config.yml
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
---
|
||||||
|
version: "1.1"
|
||||||
|
|
||||||
|
versioning:
|
||||||
|
update-major: []
|
||||||
|
update-minor: [feat]
|
||||||
|
update-patch: [fix, perf, refactor, chore, test, ci, docs]
|
||||||
|
|
||||||
|
tag:
|
||||||
|
pattern: "v%d.%d.%d"
|
||||||
|
|
||||||
|
release-notes:
|
||||||
|
sections:
|
||||||
|
- name: Features
|
||||||
|
commit-types: [feat]
|
||||||
|
section-type: commits
|
||||||
|
- name: Bug Fixes
|
||||||
|
commit-types: [fix]
|
||||||
|
section-type: commits
|
||||||
|
- name: Performance Improvements
|
||||||
|
commit-types: [perf]
|
||||||
|
section-type: commits
|
||||||
|
- name: Code Refactoring
|
||||||
|
commit-types: [refactor]
|
||||||
|
section-type: commits
|
||||||
|
- name: Others
|
||||||
|
commit-types: [chore]
|
||||||
|
section-type: commits
|
||||||
|
- name: Testing
|
||||||
|
commit-types: [test]
|
||||||
|
section-type: commits
|
||||||
|
- name: CI Pipeline
|
||||||
|
commit-types: [ci]
|
||||||
|
section-type: commits
|
||||||
|
- name: Documentation
|
||||||
|
commit-types: [docs]
|
||||||
|
section-type: commits
|
||||||
|
- name: Breaking Changes
|
||||||
|
section-type: breaking-changes
|
||||||
|
|
||||||
|
commit-message:
|
||||||
|
footer:
|
||||||
|
issue:
|
||||||
|
key: issue
|
||||||
|
add-value-prefix: "#"
|
||||||
|
issue:
|
||||||
|
regex: "#?[0-9]+"
|
1
.lycheeignore
Normal file
1
.lycheeignore
Normal file
|
@ -0,0 +1 @@
|
||||||
|
https://hub.docker.com/r/thegeeklab/*
|
|
@ -1,3 +1,2 @@
|
||||||
.drone.yml
|
|
||||||
*.tpl.md
|
*.tpl.md
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
73
.woodpecker/build-container.yml
Normal file
73
.woodpecker/build-container.yml
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
---
|
||||||
|
when:
|
||||||
|
- event: [pull_request, tag]
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: docker.io/library/python:3.12
|
||||||
|
commands:
|
||||||
|
- pip install poetry poetry-dynamic-versioning -qq
|
||||||
|
- poetry build
|
||||||
|
|
||||||
|
- name: dryrun
|
||||||
|
image: quay.io/thegeeklab/wp-docker-buildx:4
|
||||||
|
settings:
|
||||||
|
containerfile: Containerfile.multiarch
|
||||||
|
dry_run: true
|
||||||
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
provenance: false
|
||||||
|
repo: ${CI_REPO}
|
||||||
|
when:
|
||||||
|
- event: [pull_request]
|
||||||
|
|
||||||
|
- name: publish-dockerhub
|
||||||
|
image: quay.io/thegeeklab/wp-docker-buildx:4
|
||||||
|
group: container
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
containerfile: Containerfile.multiarch
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
provenance: false
|
||||||
|
repo: ${CI_REPO}
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
when:
|
||||||
|
- event: [tag]
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
|
||||||
|
- name: publish-quay
|
||||||
|
image: quay.io/thegeeklab/wp-docker-buildx:4
|
||||||
|
group: container
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
containerfile: Containerfile.multiarch
|
||||||
|
password:
|
||||||
|
from_secret: quay_password
|
||||||
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
provenance: false
|
||||||
|
registry: quay.io
|
||||||
|
repo: quay.io/${CI_REPO}
|
||||||
|
username:
|
||||||
|
from_secret: quay_username
|
||||||
|
when:
|
||||||
|
- event: [tag]
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- lint
|
||||||
|
- test
|
56
.woodpecker/build-package.yml
Normal file
56
.woodpecker/build-package.yml
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
---
|
||||||
|
when:
|
||||||
|
- event: [pull_request, tag]
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: docker.io/library/python:3.12
|
||||||
|
commands:
|
||||||
|
- pip install poetry poetry-dynamic-versioning -qq
|
||||||
|
- poetry build
|
||||||
|
|
||||||
|
- name: checksum
|
||||||
|
image: quay.io/thegeeklab/alpine-tools
|
||||||
|
commands:
|
||||||
|
- cd dist/ && sha256sum * > ../sha256sum.txt
|
||||||
|
|
||||||
|
- name: changelog
|
||||||
|
image: quay.io/thegeeklab/git-sv
|
||||||
|
commands:
|
||||||
|
- git sv current-version
|
||||||
|
- git sv release-notes -t ${CI_COMMIT_TAG:-next} -o CHANGELOG.md
|
||||||
|
- cat CHANGELOG.md
|
||||||
|
|
||||||
|
- name: publish-github
|
||||||
|
image: docker.io/plugins/github-release
|
||||||
|
settings:
|
||||||
|
api_key:
|
||||||
|
from_secret: github_token
|
||||||
|
files:
|
||||||
|
- dist/*
|
||||||
|
- sha256sum.txt
|
||||||
|
note: CHANGELOG.md
|
||||||
|
overwrite: true
|
||||||
|
title: ${CI_COMMIT_TAG}
|
||||||
|
when:
|
||||||
|
- event: [tag]
|
||||||
|
|
||||||
|
- name: publish-pypi
|
||||||
|
image: docker.io/library/python:3.12
|
||||||
|
secrets:
|
||||||
|
- source: pypi_password
|
||||||
|
target: POETRY_HTTP_BASIC_PYPI_PASSWORD
|
||||||
|
- source: pypi_username
|
||||||
|
target: POETRY_HTTP_BASIC_PYPI_USERNAME
|
||||||
|
commands:
|
||||||
|
- pip install poetry poetry-dynamic-versioning -qq
|
||||||
|
- poetry publish -n
|
||||||
|
when:
|
||||||
|
- event: [tag]
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- lint
|
||||||
|
- test
|
100
.woodpecker/docs.yml
Normal file
100
.woodpecker/docs.yml
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
---
|
||||||
|
when:
|
||||||
|
- event: [pull_request, tag]
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: assets
|
||||||
|
image: quay.io/thegeeklab/alpine-tools
|
||||||
|
commands:
|
||||||
|
- make doc
|
||||||
|
|
||||||
|
- name: markdownlint
|
||||||
|
image: quay.io/thegeeklab/markdownlint-cli
|
||||||
|
group: test
|
||||||
|
commands:
|
||||||
|
- markdownlint 'README.md' 'CONTRIBUTING.md'
|
||||||
|
|
||||||
|
- name: spellcheck
|
||||||
|
image: quay.io/thegeeklab/alpine-tools
|
||||||
|
group: test
|
||||||
|
commands:
|
||||||
|
- spellchecker --files 'docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls
|
||||||
|
environment:
|
||||||
|
FORCE_COLOR: "true"
|
||||||
|
|
||||||
|
- name: link-validation
|
||||||
|
image: docker.io/lycheeverse/lychee
|
||||||
|
group: test
|
||||||
|
commands:
|
||||||
|
- lychee --no-progress --format detailed docs/content README.md
|
||||||
|
|
||||||
|
- name: build
|
||||||
|
image: quay.io/thegeeklab/hugo:0.125.7
|
||||||
|
commands:
|
||||||
|
- hugo --panicOnWarning -s docs/
|
||||||
|
|
||||||
|
- name: beautify
|
||||||
|
image: quay.io/thegeeklab/alpine-tools
|
||||||
|
commands:
|
||||||
|
- html-beautify -r -f 'docs/public/**/*.html'
|
||||||
|
environment:
|
||||||
|
FORCE_COLOR: "true"
|
||||||
|
|
||||||
|
- name: publish
|
||||||
|
image: quay.io/thegeeklab/wp-s3-action
|
||||||
|
settings:
|
||||||
|
access_key:
|
||||||
|
from_secret: s3_access_key
|
||||||
|
bucket: geekdocs
|
||||||
|
delete: true
|
||||||
|
endpoint:
|
||||||
|
from_secret: s3_endpoint
|
||||||
|
path_style: true
|
||||||
|
secret_key:
|
||||||
|
from_secret: s3_secret_access_key
|
||||||
|
source: docs/public/
|
||||||
|
strip_prefix: docs/public/
|
||||||
|
target: /${CI_REPO_NAME}
|
||||||
|
when:
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
status: [success, failure]
|
||||||
|
|
||||||
|
- name: pushrm-dockerhub
|
||||||
|
image: docker.io/chko/docker-pushrm:1
|
||||||
|
secrets:
|
||||||
|
- source: docker_password
|
||||||
|
target: DOCKER_PASS
|
||||||
|
- source: docker_username
|
||||||
|
target: DOCKER_USER
|
||||||
|
environment:
|
||||||
|
PUSHRM_FILE: README.md
|
||||||
|
PUSHRM_SHORT: Prometheus Service Discovery for Proxmox VE
|
||||||
|
PUSHRM_TARGET: ${CI_REPO}
|
||||||
|
when:
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
status: [success]
|
||||||
|
|
||||||
|
- name: pushrm-quay
|
||||||
|
image: docker.io/chko/docker-pushrm:1
|
||||||
|
secrets:
|
||||||
|
- source: quay_token
|
||||||
|
target: APIKEY__QUAY_IO
|
||||||
|
environment:
|
||||||
|
PUSHRM_FILE: README.md
|
||||||
|
PUSHRM_TARGET: quay.io/${CI_REPO}
|
||||||
|
when:
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
status: [success]
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- build-package
|
||||||
|
- build-container
|
25
.woodpecker/lint.yml
Normal file
25
.woodpecker/lint.yml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
when:
|
||||||
|
- event: [pull_request, tag]
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: check-format
|
||||||
|
image: docker.io/library/python:3.12
|
||||||
|
commands:
|
||||||
|
- pip install poetry poetry-dynamic-versioning -qq
|
||||||
|
- poetry install
|
||||||
|
- poetry run ruff format --check --diff ./${CI_REPO_NAME//-/}
|
||||||
|
environment:
|
||||||
|
PY_COLORS: "1"
|
||||||
|
|
||||||
|
- name: check-coding
|
||||||
|
image: docker.io/library/python:3.12
|
||||||
|
commands:
|
||||||
|
- pip install poetry poetry-dynamic-versioning -qq
|
||||||
|
- poetry install
|
||||||
|
- poetry run ruff check ./${CI_REPO_NAME//-/}
|
||||||
|
environment:
|
||||||
|
PY_COLORS: "1"
|
26
.woodpecker/notify.yml
Normal file
26
.woodpecker/notify.yml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
---
|
||||||
|
when:
|
||||||
|
- event: [tag]
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
|
||||||
|
runs_on: [success, failure]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: matrix
|
||||||
|
image: quay.io/thegeeklab/wp-matrix
|
||||||
|
settings:
|
||||||
|
homeserver:
|
||||||
|
from_secret: matrix_homeserver
|
||||||
|
password:
|
||||||
|
from_secret: matrix_password
|
||||||
|
roomid:
|
||||||
|
from_secret: matrix_roomid
|
||||||
|
username:
|
||||||
|
from_secret: matrix_username
|
||||||
|
when:
|
||||||
|
- status: [success, failure]
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- docs
|
39
.woodpecker/test.yml
Normal file
39
.woodpecker/test.yml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
---
|
||||||
|
when:
|
||||||
|
- event: [pull_request, tag]
|
||||||
|
- event: [push, manual]
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
|
||||||
|
variables:
|
||||||
|
- &pytest_base
|
||||||
|
group: pytest
|
||||||
|
commands:
|
||||||
|
- pip install poetry poetry-dynamic-versioning -qq
|
||||||
|
- poetry install
|
||||||
|
- poetry run pytest --cov-append
|
||||||
|
- poetry version
|
||||||
|
- poetry run ${CI_REPO_NAME} --help
|
||||||
|
environment:
|
||||||
|
PY_COLORS: "1"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: python-312
|
||||||
|
image: docker.io/library/python:3.12
|
||||||
|
<<: *pytest_base
|
||||||
|
|
||||||
|
- name: python-311
|
||||||
|
image: docker.io/library/python:3.11
|
||||||
|
<<: *pytest_base
|
||||||
|
|
||||||
|
- name: python-310
|
||||||
|
image: docker.io/library/python:3.10
|
||||||
|
<<: *pytest_base
|
||||||
|
|
||||||
|
- name: python-39
|
||||||
|
image: docker.io/library/python:3.9
|
||||||
|
<<: *pytest_base
|
||||||
|
|
||||||
|
- name: python-38
|
||||||
|
image: docker.io/library/python:3.8
|
||||||
|
<<: *pytest_base
|
|
@ -3,7 +3,7 @@
|
||||||
## Security
|
## Security
|
||||||
|
|
||||||
If you think you have found a **security issue**, please do not mention it in this repository.
|
If you think you have found a **security issue**, please do not mention it in this repository.
|
||||||
Instead, send an email to security@thegeeklab.de with as many details as possible so it can be handled confidential.
|
Instead, send an email to `security@thegeeklab.de` with as many details as possible so it can be handled confidential.
|
||||||
|
|
||||||
## Bug Reports and Feature Requests
|
## Bug Reports and Feature Requests
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM python:3.10-alpine@sha256:a9865ba6472324621e81e1da5cbd02069d528215a4b49d49695eac693c10488a
|
FROM python:3.12-alpine@sha256:5365725a6cd59b72a927628fdda9965103e3dc671676c89ef3ed8b8b0e22e812
|
||||||
|
|
||||||
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
||||||
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
||||||
# renovate: datasource=github-releases depName=thegeeklab/hugo-geekdoc
|
# renovate: datasource=github-releases depName=thegeeklab/hugo-geekdoc
|
||||||
THEME_VERSION := v0.27.3
|
THEME_VERSION := v0.45.0
|
||||||
THEME := hugo-geekdoc
|
THEME := hugo-geekdoc
|
||||||
BASEDIR := docs
|
BASEDIR := docs
|
||||||
THEMEDIR := $(BASEDIR)/themes
|
THEMEDIR := $(BASEDIR)/themes
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Prometheus Service Discovery for Proxmox VE
|
Prometheus Service Discovery for Proxmox VE
|
||||||
|
|
||||||
[![Build Status](https://img.shields.io/drone/build/thegeeklab/prometheus-pve-sd?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/prometheus-pve-sd)
|
[![Build Status](https://ci.thegeeklab.de/api/badges/thegeeklab/prometheus-pve-sd/status.svg)](https://ci.thegeeklab.de/repos/thegeeklab/prometheus-pve-sd)
|
||||||
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/prometheus-pve-sd)
|
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/prometheus-pve-sd)
|
||||||
[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/prometheus-pve-sd)
|
[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/prometheus-pve-sd)
|
||||||
[![Python Version](https://img.shields.io/pypi/pyversions/prometheus-pve-sd.svg)](https://pypi.org/project/prometheus-pve-sd/)
|
[![Python Version](https://img.shields.io/pypi/pyversions/prometheus-pve-sd.svg)](https://pypi.org/project/prometheus-pve-sd/)
|
||||||
|
@ -12,13 +12,13 @@ Prometheus Service Discovery for Proxmox VE
|
||||||
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/prometheus-pve-sd)
|
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/prometheus-pve-sd)
|
||||||
[![License: MIT](https://img.shields.io/github/license/thegeeklab/prometheus-pve-sd)](https://github.com/thegeeklab/prometheus-pve-sd/blob/main/LICENSE)
|
[![License: MIT](https://img.shields.io/github/license/thegeeklab/prometheus-pve-sd)](https://github.com/thegeeklab/prometheus-pve-sd/blob/main/LICENSE)
|
||||||
|
|
||||||
This project provides a simple custom service discovery for [Prometheus](https://prometheus.io/). It is using the Proxmox PVE API to fetch Hosts and it's meta information to generate a Prometheus compatible [file based](https://prometheus.io/docs/guides/file-sd/) service discovery. Releases are available as Python Packages on [GitHub](https://github.com/thegeeklab/prometheus-pve-sd/releases) or [PyPI](https://pypi.org/project/prometheus-pve-sd/) and as Docker Image on [Docker Hub](https://hub.docker.com/r/thegeeklab/prometheus-pve-sd).
|
This project provides a simple custom service discovery for [Prometheus](https://prometheus.io/). It is using the [Proxmox VE](https://www.proxmox.com/de/proxmox-ve) (PVE) API to fetch Hosts and it's meta information to generate a Prometheus compatible [file based](https://prometheus.io/docs/guides/file-sd/) service discovery. Releases are available as Python Packages on [GitHub](https://github.com/thegeeklab/prometheus-pve-sd/releases) or [PyPI](https://pypi.org/project/prometheus-pve-sd/) and as Docker Image on [Docker Hub](https://hub.docker.com/r/thegeeklab/prometheus-pve-sd).
|
||||||
|
|
||||||
You can find the full documentation at [https://prometheus-pve-sd.geekdocs.de](https://prometheus-pve-sd.geekdocs.de).
|
You can find the full documentation at [https://prometheus-pve-sd.geekdocs.de](https://prometheus-pve-sd.geekdocs.de).
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
Special thanks goes to all [contributors](https://github.com/thegeeklab/prometheus-pve-sd/graphs/contributors). If you would like to contribute,
|
Special thanks to all [contributors](https://github.com/thegeeklab/prometheus-pve-sd/graphs/contributors). If you would like to contribute,
|
||||||
please see the [instructions](https://github.com/thegeeklab/prometheus-pve-sd/blob/main/CONTRIBUTING.md).
|
please see the [instructions](https://github.com/thegeeklab/prometheus-pve-sd/blob/main/CONTRIBUTING.md).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
21
codecov.yml
21
codecov.yml
|
@ -1,21 +0,0 @@
|
||||||
codecov:
|
|
||||||
require_ci_to_pass: true
|
|
||||||
coverage:
|
|
||||||
status:
|
|
||||||
project:
|
|
||||||
default:
|
|
||||||
target: auto
|
|
||||||
threshold: 5%
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
if_ci_failed: error
|
|
||||||
informational: false
|
|
||||||
only_pulls: false
|
|
||||||
patch:
|
|
||||||
default:
|
|
||||||
target: auto
|
|
||||||
threshold: 5%
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
if_ci_failed: error
|
|
||||||
only_pulls: false
|
|
|
@ -1,24 +0,0 @@
|
||||||
FROM arm32v7/python:3.10-alpine@sha256:9871be3035a0832069bdb8fb5c486025af6d0c0a77e1111bbc1807f638a5e2b6
|
|
||||||
|
|
||||||
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
|
||||||
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
|
||||||
LABEL org.opencontainers.image.title="prometheus-pve-sd"
|
|
||||||
LABEL org.opencontainers.image.url="https://github.com/thegeeklab/prometheus-pve-sd/"
|
|
||||||
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/prometheus-pve-sd/"
|
|
||||||
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/prometheus-pve-sd/"
|
|
||||||
|
|
||||||
ENV PY_COLORS=1
|
|
||||||
ENV TZ=UTC
|
|
||||||
|
|
||||||
ADD dist/prometheus_pve_sd-*.whl /
|
|
||||||
|
|
||||||
RUN apk --update add --virtual .build-deps build-base libffi-dev openssl-dev && \
|
|
||||||
pip install --upgrade --no-cache-dir pip && \
|
|
||||||
pip install --no-cache-dir $(find / -name "prometheus_pve_sd-*.whl") && \
|
|
||||||
rm -f prometheus_pve_sd-*.whl && \
|
|
||||||
rm -rf /var/cache/apk/* && \
|
|
||||||
rm -rf /root/.cache/
|
|
||||||
|
|
||||||
USER root
|
|
||||||
CMD []
|
|
||||||
ENTRYPOINT ["/usr/local/bin/prometheus-pve-sd"]
|
|
|
@ -1,24 +0,0 @@
|
||||||
FROM arm64v8/python:3.10-alpine@sha256:5fae85eea1d49fa7e0b60ab7091922329d1f573a3359f9dc438ac0614169c22a
|
|
||||||
|
|
||||||
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
|
||||||
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
|
||||||
LABEL org.opencontainers.image.title="prometheus-pve-sd"
|
|
||||||
LABEL org.opencontainers.image.url="https://github.com/thegeeklab/prometheus-pve-sd/"
|
|
||||||
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/prometheus-pve-sd/"
|
|
||||||
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/prometheus-pve-sd/"
|
|
||||||
|
|
||||||
ENV PY_COLORS=1
|
|
||||||
ENV TZ=UTC
|
|
||||||
|
|
||||||
ADD dist/prometheus_pve_sd-*.whl /
|
|
||||||
|
|
||||||
RUN apk --update add --virtual .build-deps build-base libffi-dev openssl-dev && \
|
|
||||||
pip install --upgrade --no-cache-dir pip && \
|
|
||||||
pip install --no-cache-dir $(find / -name "prometheus_pve_sd-*.whl") && \
|
|
||||||
rm -f prometheus_pve_sd-*.whl && \
|
|
||||||
rm -rf /var/cache/apk/* && \
|
|
||||||
rm -rf /root/.cache/
|
|
||||||
|
|
||||||
USER root
|
|
||||||
CMD []
|
|
||||||
ENTRYPOINT ["/usr/local/bin/prometheus-pve-sd"]
|
|
|
@ -1,24 +0,0 @@
|
||||||
image: quay.io/thegeeklab/prometheus-pve-sd:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
|
||||||
{{#if build.tags}}
|
|
||||||
tags:
|
|
||||||
{{#each build.tags}}
|
|
||||||
- {{this}}
|
|
||||||
{{/each}}
|
|
||||||
{{/if}}
|
|
||||||
manifests:
|
|
||||||
- image: quay.io/thegeeklab/prometheus-pve-sd:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64
|
|
||||||
platform:
|
|
||||||
architecture: amd64
|
|
||||||
os: linux
|
|
||||||
|
|
||||||
- image: quay.io/thegeeklab/prometheus-pve-sd:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64
|
|
||||||
platform:
|
|
||||||
architecture: arm64
|
|
||||||
os: linux
|
|
||||||
variant: v8
|
|
||||||
|
|
||||||
- image: quay.io/thegeeklab/prometheus-pve-sd:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm
|
|
||||||
platform:
|
|
||||||
architecture: arm
|
|
||||||
os: linux
|
|
||||||
variant: v7
|
|
|
@ -1,24 +0,0 @@
|
||||||
image: thegeeklab/prometheus-pve-sd:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
|
||||||
{{#if build.tags}}
|
|
||||||
tags:
|
|
||||||
{{#each build.tags}}
|
|
||||||
- {{this}}
|
|
||||||
{{/each}}
|
|
||||||
{{/if}}
|
|
||||||
manifests:
|
|
||||||
- image: thegeeklab/prometheus-pve-sd:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64
|
|
||||||
platform:
|
|
||||||
architecture: amd64
|
|
||||||
os: linux
|
|
||||||
|
|
||||||
- image: thegeeklab/prometheus-pve-sd:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64
|
|
||||||
platform:
|
|
||||||
architecture: arm64
|
|
||||||
os: linux
|
|
||||||
variant: v8
|
|
||||||
|
|
||||||
- image: thegeeklab/prometheus-pve-sd:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm
|
|
||||||
platform:
|
|
||||||
architecture: arm
|
|
||||||
os: linux
|
|
||||||
variant: v7
|
|
0
docs/.drone.yml
Normal file
0
docs/.drone.yml
Normal file
0
docs/.hugo_build.lock
Normal file
0
docs/.hugo_build.lock
Normal file
|
@ -19,7 +19,7 @@ markup:
|
||||||
|
|
||||||
params:
|
params:
|
||||||
description: >
|
description: >
|
||||||
prometheus-pve-sd is a simple custom service discovery for Prometheus. It is using the Proxmox PVE API
|
prometheus-pve-sd is a simple custom service discovery for Prometheus. It is using the Proxmox VE API
|
||||||
to fetch Hosts and it's meta information to generate a Prometheus compatible file based service discovery.
|
to fetch Hosts and it's meta information to generate a Prometheus compatible file based service discovery.
|
||||||
images:
|
images:
|
||||||
- "socialmedia2.png"
|
- "socialmedia2.png"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
title: Documentation
|
title: Documentation
|
||||||
---
|
---
|
||||||
|
|
||||||
[![Build Status](https://img.shields.io/drone/build/thegeeklab/prometheus-pve-sd?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/prometheus-pve-sd)
|
[![Build Status](https://ci.thegeeklab.de/api/badges/thegeeklab/prometheus-pve-sd/status.svg)](https://ci.thegeeklab.de/repos/thegeeklab/prometheus-pve-sd)
|
||||||
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/prometheus-pve-sd)
|
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/prometheus-pve-sd)
|
||||||
[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/prometheus-pve-sd)
|
[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/prometheus-pve-sd)
|
||||||
[![Python Version](https://img.shields.io/pypi/pyversions/prometheus-pve-sd.svg)](https://pypi.org/project/prometheus-pve-sd/)
|
[![Python Version](https://img.shields.io/pypi/pyversions/prometheus-pve-sd.svg)](https://pypi.org/project/prometheus-pve-sd/)
|
||||||
|
@ -12,4 +12,4 @@ title: Documentation
|
||||||
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/prometheus-pve-sd)
|
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/prometheus-pve-sd)
|
||||||
[![License: MIT](https://img.shields.io/github/license/thegeeklab/prometheus-pve-sd)](https://github.com/thegeeklab/prometheus-pve-sd/blob/main/LICENSE)
|
[![License: MIT](https://img.shields.io/github/license/thegeeklab/prometheus-pve-sd)](https://github.com/thegeeklab/prometheus-pve-sd/blob/main/LICENSE)
|
||||||
|
|
||||||
This project provides a simple custom service discovery for [Prometheus](https://prometheus.io/). It is using the Proxmox PVE API to fetch Hosts and it's meta information to generate a Prometheus compatible [file based](https://prometheus.io/docs/guides/file-sd/) service discovery. Releases are available as Python Packages on [GitHub](https://github.com/thegeeklab/prometheus-pve-sd/releases) or [PyPI](https://pypi.org/project/prometheus-pve-sd/) and as Docker Image on [Docker Hub](https://hub.docker.com/r/thegeeklab/prometheus-pve-sd).
|
This project provides a simple custom service discovery for [Prometheus](https://prometheus.io/). It is using the [Proxmox VE](https://www.proxmox.com/de/proxmox-ve) (PVE) API to fetch Hosts and it's meta information to generate a Prometheus compatible [file based](https://prometheus.io/docs/guides/file-sd/) service discovery. Releases are available as Python Packages on [GitHub](https://github.com/thegeeklab/prometheus-pve-sd/releases) or [PyPI](https://pypi.org/project/prometheus-pve-sd/) and as Docker Image on [Docker Hub](https://hub.docker.com/r/thegeeklab/prometheus-pve-sd).
|
||||||
|
|
|
@ -4,20 +4,20 @@ title: CLI options
|
||||||
|
|
||||||
You can get all available CLI options by running `prometheus-pve-sd --help`:
|
You can get all available CLI options by running `prometheus-pve-sd --help`:
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
```Shell
|
||||||
<!-- spellchecker-disable -->
|
|
||||||
{{< highlight Shell "linenos=table" >}}
|
|
||||||
$ prometheus-pve-sd --help
|
$ prometheus-pve-sd --help
|
||||||
usage: prometheus-pve-sd [-h] [-c CONFIG_FILE] [-o OUTPUT_FILE] [-d LOOP_DELAY] [--no-service] [-f LOG_FORMAT] [-v] [-q] [--version]
|
usage: prometheus-pve-sd [-h] [-c CONFIG_FILE] [-o OUTPUT_FILE] [-m OUTPUT_FILE_MODE] [-d LOOP_DELAY] [--no-service] [-f LOG_FORMAT] [-v] [-q] [--version]
|
||||||
|
|
||||||
Prometheus Service Discovery for Proxmox VE
|
Prometheus Service Discovery for Proxmox VE
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-c CONFIG_FILE, --config CONFIG_FILE
|
-c CONFIG_FILE, --config CONFIG_FILE
|
||||||
location of configuration file
|
location of configuration file
|
||||||
-o OUTPUT_FILE, --output OUTPUT_FILE
|
-o OUTPUT_FILE, --output OUTPUT_FILE
|
||||||
output file
|
output file
|
||||||
|
-m OUTPUT_FILE_MODE, --mode OUTPUT_FILE_MODE
|
||||||
|
output file mode
|
||||||
-d LOOP_DELAY, --loop-delay LOOP_DELAY
|
-d LOOP_DELAY, --loop-delay LOOP_DELAY
|
||||||
delay between discovery runs
|
delay between discovery runs
|
||||||
--no-service run discovery only once
|
--no-service run discovery only once
|
||||||
|
@ -26,6 +26,4 @@ optional arguments:
|
||||||
-v increase log level
|
-v increase log level
|
||||||
-q decrease log level
|
-q decrease log level
|
||||||
--version show program's version number and exit
|
--version show program's version number and exit
|
||||||
{{< /highlight >}}
|
```
|
||||||
<!-- spellchecker-enable -->
|
|
||||||
<!-- prettier-ignore-end -->
|
|
||||||
|
|
|
@ -2,15 +2,12 @@
|
||||||
title: Default settings
|
title: Default settings
|
||||||
---
|
---
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
```Shell
|
||||||
<!-- markdownlint-disable -->
|
|
||||||
<!-- spellchecker-disable -->
|
|
||||||
{{< highlight YAML "linenos=table" >}}
|
|
||||||
---
|
---
|
||||||
logging:
|
logging:
|
||||||
# supported log levels: debug|info|warning|error|critical
|
# Supported log levels: debug|info|warning|error|critical
|
||||||
level: warning
|
level: warning
|
||||||
# supported log formats: console|json|simple
|
# Supported log formats: console|json|simple
|
||||||
format: console
|
format: console
|
||||||
|
|
||||||
metrics:
|
metrics:
|
||||||
|
@ -19,30 +16,49 @@ metrics:
|
||||||
port: 8000
|
port: 8000
|
||||||
|
|
||||||
output_file:
|
output_file:
|
||||||
|
output_file_mode: "0640"
|
||||||
|
|
||||||
loop_delay: 300
|
loop_delay: 300
|
||||||
# Run pve sd in a loop and discover hosts every n seconds (as defined in loop_delay).
|
# Run pve sd in a loop and discover hosts every n seconds (as defined in loop_delay).
|
||||||
# Can be disabled to run disovery only once.
|
# Can be disabled to run disovery only once.
|
||||||
service: true
|
service: true
|
||||||
|
|
||||||
exclude_state: []
|
exclude_state: []
|
||||||
# needs to be a list of strings
|
|
||||||
exclude_vmid: []
|
|
||||||
|
|
||||||
|
# Needs to be a list of strings.
|
||||||
|
exclude_vmid: []
|
||||||
|
include_vmid: []
|
||||||
|
|
||||||
|
# Can be used to exclude vms by tags (proxmox 6+) - needs to be a list of strings.
|
||||||
|
# If `include_tags` and `exclude_tags` are set at the same time, the `exclude_tags` option takes precedence.
|
||||||
|
# If `include_tags` is set, and your VM don't have any tags set, they will not show up!
|
||||||
|
exclude_tags: []
|
||||||
|
include_tags: []
|
||||||
|
|
||||||
|
# Set either password or token_name and token_value
|
||||||
pve:
|
pve:
|
||||||
server:
|
server:
|
||||||
user:
|
user:
|
||||||
password
|
password:
|
||||||
|
token_name:
|
||||||
|
token_value:
|
||||||
auth_timeout: 5
|
auth_timeout: 5
|
||||||
verify_ssl: true
|
verify_ssl: true
|
||||||
|
|
||||||
# Example
|
# Example with password
|
||||||
# pve:
|
# pve:
|
||||||
# server: proxmox.example.com
|
# server: proxmox.example.com
|
||||||
# user: root
|
# user: root
|
||||||
# password: secure
|
# password: secure
|
||||||
# auth_timeout: 5
|
# auth_timeout: 5
|
||||||
# verify_ssl: true
|
# verify_ssl: true
|
||||||
{{< /highlight >}}
|
|
||||||
<!-- spellchecker-enable -->
|
# Example with API token
|
||||||
<!-- markdownlint-restore -->
|
# pve:
|
||||||
<!-- prettier-ignore-end -->
|
# server: proxmox.example.com
|
||||||
|
# user: root
|
||||||
|
# token_name: pve_sd
|
||||||
|
# token_value: 01234567-89ab-cdef-0123-456789abcdef
|
||||||
|
# auth_timeout: 5
|
||||||
|
# verify_ssl: true
|
||||||
|
```
|
||||||
|
|
|
@ -2,10 +2,7 @@
|
||||||
title: Environment Variables
|
title: Environment Variables
|
||||||
---
|
---
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
```Shell
|
||||||
<!-- markdownlint-disable -->
|
|
||||||
<!-- spellchecker-disable -->
|
|
||||||
{{< highlight Shell "linenos=table" >}}
|
|
||||||
PROMETHEUS_PVE_SD_CONFIG_FILE=
|
PROMETHEUS_PVE_SD_CONFIG_FILE=
|
||||||
|
|
||||||
# supported log levels: debug|info|warning|error|critical
|
# supported log levels: debug|info|warning|error|critical
|
||||||
|
@ -18,6 +15,8 @@ PROMETHEUS_PVE_SD_METRICS_ADDRESS=127.0.01
|
||||||
PROMETHEUS_PVE_SD_METRICS_PORT=8000
|
PROMETHEUS_PVE_SD_METRICS_PORT=8000
|
||||||
|
|
||||||
PROMETHEUS_PVE_SD_OUTPUT_FILE=
|
PROMETHEUS_PVE_SD_OUTPUT_FILE=
|
||||||
|
PROMETHEUS_PVE_SD_OUTPUT_FILE_MODE=0640
|
||||||
|
|
||||||
PROMETHEUS_PVE_SD_LOOP_DELAY=300
|
PROMETHEUS_PVE_SD_LOOP_DELAY=300
|
||||||
|
|
||||||
# Run PVE SD in a loop and discover hosts every n seconds (as defined in PROMETHEUS_PVE_SD_LOOP_DELAY).
|
# Run PVE SD in a loop and discover hosts every n seconds (as defined in PROMETHEUS_PVE_SD_LOOP_DELAY).
|
||||||
|
@ -25,14 +24,20 @@ PROMETHEUS_PVE_SD_LOOP_DELAY=300
|
||||||
PROMETHEUS_PVE_SD_SERVICE=true
|
PROMETHEUS_PVE_SD_SERVICE=true
|
||||||
|
|
||||||
PROMETHEUS_PVE_SD_EXCLUDE_STATE=
|
PROMETHEUS_PVE_SD_EXCLUDE_STATE=
|
||||||
|
|
||||||
|
# comma-separated list
|
||||||
PROMETHEUS_PVE_SD_EXCLUDE_VMID=
|
PROMETHEUS_PVE_SD_EXCLUDE_VMID=
|
||||||
|
PROMETHEUS_PVE_SD_INCLUDE_VMID=
|
||||||
|
|
||||||
|
# comma-separated list
|
||||||
|
PROMETHEUS_PVE_SD_EXCLUDE_TAGS=
|
||||||
|
PROMETHEUS_PVE_SD_INCLUDE_TAGS=
|
||||||
|
|
||||||
PROMETHEUS_PVE_SD_PVE_SERVER=
|
PROMETHEUS_PVE_SD_PVE_SERVER=
|
||||||
PROMETHEUS_PVE_SD_PVE_USER=
|
PROMETHEUS_PVE_SD_PVE_USER=
|
||||||
PROMETHEUS_PVE_SD_PVE_PASSWORD=
|
PROMETHEUS_PVE_SD_PVE_PASSWORD=
|
||||||
|
PROMETHEUS_PVE_SD_PVE_TOKEN_NAME=
|
||||||
|
PROMETHEUS_PVE_SD_PVE_TOKEN_VALUE=
|
||||||
PROMETHEUS_PVE_SD_PVE_AUTH_TIMEOUT=5
|
PROMETHEUS_PVE_SD_PVE_AUTH_TIMEOUT=5
|
||||||
PROMETHEUS_PVE_SD_PVE_VERIFY_SSL=true
|
PROMETHEUS_PVE_SD_PVE_VERIFY_SSL=true
|
||||||
{{< /highlight >}}
|
```
|
||||||
<!-- spellchecker-enable -->
|
|
||||||
<!-- markdownlint-restore -->
|
|
||||||
<!-- prettier-ignore-end -->
|
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
title: Using docker
|
title: Using docker
|
||||||
---
|
---
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
```Shell
|
||||||
<!-- spellchecker-disable -->
|
|
||||||
{{< highlight Shell "linenos=table" >}}
|
|
||||||
docker run \
|
docker run \
|
||||||
-e PROMETHEUS_PVE_SD_LOG_LEVEL=info \
|
-e PROMETHEUS_PVE_SD_LOG_LEVEL=info \
|
||||||
-e PROMETHEUS_PVE_SD_LOG_FORMAT=console \
|
-e PROMETHEUS_PVE_SD_LOG_FORMAT=console \
|
||||||
|
@ -16,11 +14,10 @@ docker run \
|
||||||
-e PY_COLORS=1 \
|
-e PY_COLORS=1 \
|
||||||
-v $(pwd):/out \
|
-v $(pwd):/out \
|
||||||
thegeeklab/prometheus-pve-sd
|
thegeeklab/prometheus-pve-sd
|
||||||
{{< /highlight >}}
|
```
|
||||||
<!-- spellchecker-enable -->
|
|
||||||
<!-- prettier-ignore-end -->
|
|
||||||
|
|
||||||
{{< hint info >}}
|
{{< hint type=note >}}
|
||||||
**Info**\
|
|
||||||
Keep in mind, that you have to pass SELinux labels (:Z or :z) to your mount option if you are working on SELinux enabled systems.
|
Keep in mind, that you have to pass SELinux labels (:Z or :z) to your mount option if you are working on SELinux enabled systems.
|
||||||
{{< /hint >}}
|
{{< /hint >}}
|
||||||
|
|
||||||
|
After configuring and starting the service, Prometheus need to be [configured](/usage/getting-started/#prometheus-configuration) to use the external service discovery.
|
||||||
|
|
|
@ -2,10 +2,7 @@
|
||||||
title: Using pip
|
title: Using pip
|
||||||
---
|
---
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
```Shell
|
||||||
<!-- markdownlint-disable -->
|
|
||||||
<!-- spellchecker-disable -->
|
|
||||||
{{< highlight Shell "linenos=table" >}}
|
|
||||||
# From PyPI as unprivileged user
|
# From PyPI as unprivileged user
|
||||||
$ pip install prometheus-pve-sd --user
|
$ pip install prometheus-pve-sd --user
|
||||||
|
|
||||||
|
@ -14,7 +11,12 @@ $ sudo pip install prometheus-pve-sd
|
||||||
|
|
||||||
# From Wheel file
|
# From Wheel file
|
||||||
$ pip install https://github.com/thegeeklab/prometheus-pve-sd/releases/download/v0.1.0/prometheus_pve_sd-0.1.0-py3-none-any.whl
|
$ pip install https://github.com/thegeeklab/prometheus-pve-sd/releases/download/v0.1.0/prometheus_pve_sd-0.1.0-py3-none-any.whl
|
||||||
{{< /highlight >}}
|
```
|
||||||
<!-- spellchecker-enable -->
|
|
||||||
<!-- markdownlint-restore -->
|
Start the service:
|
||||||
<!-- prettier-ignore-end -->
|
|
||||||
|
```Shell
|
||||||
|
prometheus-pve-sd -vv --loop-delay 900 -o /etc/prometheus/pve.json
|
||||||
|
```
|
||||||
|
|
||||||
|
After configuring and starting the service, Prometheus need to be [configured](/usage/getting-started/#prometheus-configuration) to use the external service discovery.
|
||||||
|
|
80
docs/content/setup/prometheus-operator.md
Normal file
80
docs/content/setup/prometheus-operator.md
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
---
|
||||||
|
title: Using Prometheus Operator
|
||||||
|
---
|
||||||
|
|
||||||
|
{{< toc >}}
|
||||||
|
|
||||||
|
As an alternative to local files service discovery Prometheus also support discoveries form HTTP endpoints. In a Kubernetes setup, with the Prometheus operator, it makes more sense to use this [HTTP SD](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_sd_config) instead of mounting the output file of the `prometheus-pve-sd` to the container.
|
||||||
|
|
||||||
|
The `prometheus-pve-sd` module doesn't have a dedicated HTTP endpoint, therefore you need to use a web server sidecar, that hosts the static file. The following deployment configuration can serve as a starting point for most setups, and just requires some minor adjustments, depending on your Kubernetes setup.
|
||||||
|
|
||||||
|
## Kubernetes configuration
|
||||||
|
|
||||||
|
Deployment configuration:
|
||||||
|
|
||||||
|
```YAML
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
creationTimestamp: null
|
||||||
|
labels:
|
||||||
|
app: proxmox-service-discovery
|
||||||
|
name: proxmox-service-discovery
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: proxmox-service-discovery
|
||||||
|
strategy: {}
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
creationTimestamp: null
|
||||||
|
labels:
|
||||||
|
app: proxmox-service-discovery
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx
|
||||||
|
name: webserver
|
||||||
|
resources: {}
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
protocol: TCP
|
||||||
|
name: http
|
||||||
|
volumeMounts:
|
||||||
|
- name: pve-sd-output
|
||||||
|
mountPath: /usr/share/nginx/html
|
||||||
|
- image: thegeeklab/prometheus-pve-sd
|
||||||
|
name: prometheus-pve-sd
|
||||||
|
resources: {}
|
||||||
|
env:
|
||||||
|
- name: PROMETHEUS_PVE_SD_OUTPUT_FILE
|
||||||
|
value: /tmp/pve/proxmox.json
|
||||||
|
# Add more configurations here, or use a configMap or secret to inject the remaining configs
|
||||||
|
volumeMounts:
|
||||||
|
- name: pve-sd-output
|
||||||
|
mountPath: /tmp/pve/
|
||||||
|
volumes:
|
||||||
|
- name: pve-sd-output
|
||||||
|
emptyDir: {}
|
||||||
|
status: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
Additionally you will need a service, that exposes the HTTP endpoint within Kubernetes so Prometheus can scrape it.
|
||||||
|
|
||||||
|
Service configuration:
|
||||||
|
|
||||||
|
```YAML
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: pve-sd-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: proxmox-service-discovery
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 80
|
||||||
|
targetPort: 80
|
||||||
|
```
|
||||||
|
|
||||||
|
After configuring and starting the service, Prometheus need to be [configured](/usage/getting-started/#prometheus-configuration) to use the external service discovery.
|
|
@ -1,60 +1,3 @@
|
||||||
---
|
---
|
||||||
title: Usage
|
title: Usage
|
||||||
---
|
---
|
||||||
|
|
||||||
{{< toc >}}
|
|
||||||
|
|
||||||
## Start PVE SD
|
|
||||||
|
|
||||||
Create a [configuration file](/configuration/defaults/) with the required parameters to connect to your PVE server before you start the service.
|
|
||||||
|
|
||||||
```Shell
|
|
||||||
run prometheus-pve-sd -vv --loop-delay 900 -o /etc/prometheus/pve.json
|
|
||||||
```
|
|
||||||
|
|
||||||
## Available Labels
|
|
||||||
|
|
||||||
The following list of meta labels can be used to relabel your scrape results:
|
|
||||||
|
|
||||||
`__meta_pve_ipv4`
|
|
||||||
|
|
||||||
`__meta_pve_ipv6`
|
|
||||||
|
|
||||||
`__meta_pve_name`
|
|
||||||
|
|
||||||
`__meta_pve_type`
|
|
||||||
|
|
||||||
`__meta_pve_vmid`
|
|
||||||
|
|
||||||
`__meta_pve_cpu`
|
|
||||||
|
|
||||||
`__meta_pve_cores`
|
|
||||||
|
|
||||||
`__meta_pve_memory`
|
|
||||||
|
|
||||||
`__meta_pve_status`
|
|
||||||
|
|
||||||
`__meta_pve_groups`
|
|
||||||
: Groups will be discovered from the `Notes` field of a host and need to be set as JSON e.g. `{"groups":["group1","group2"]}`
|
|
||||||
|
|
||||||
## Prometheus configuration
|
|
||||||
|
|
||||||
This example configuration snippet for the Prometheus `scrape_config` Prometheus to scrape `telegraf` assuming that it is deployed on all your servers.
|
|
||||||
|
|
||||||
```YAML
|
|
||||||
- file_sd_configs:
|
|
||||||
- files:
|
|
||||||
- /opt/prometheus/conf/file_sd/proxmox.json
|
|
||||||
job_name: telegraf-pve
|
|
||||||
metrics_path: /metrics
|
|
||||||
relabel_configs:
|
|
||||||
- replacement: telegraf
|
|
||||||
target_label: job
|
|
||||||
- replacement: ${1}:9273
|
|
||||||
source_labels:
|
|
||||||
- __meta_pve_name
|
|
||||||
target_label: __address__
|
|
||||||
- source_labels:
|
|
||||||
- __meta_pve_name
|
|
||||||
target_label: instance
|
|
||||||
```
|
|
||||||
|
|
54
docs/content/usage/advanced.md
Normal file
54
docs/content/usage/advanced.md
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
---
|
||||||
|
title: Getting Started
|
||||||
|
---
|
||||||
|
|
||||||
|
{{< toc >}}
|
||||||
|
|
||||||
|
## Prometheus relabeling
|
||||||
|
|
||||||
|
### Use IP address labels
|
||||||
|
|
||||||
|
Instead of `__meta_pve_name`, it is also possible to configure Prometheus to use the address provided by `__meta_pve_ipv4` or `__meta_pve_ipv4` for connections:
|
||||||
|
|
||||||
|
```YAML
|
||||||
|
relabel_configs:
|
||||||
|
- replacement: ${1}:9273
|
||||||
|
source_labels:
|
||||||
|
- __meta_pve_ipv4
|
||||||
|
target_label: __address__
|
||||||
|
```
|
||||||
|
|
||||||
|
### Convert tags to custom labels
|
||||||
|
|
||||||
|
Tags of a node exposed by the `__meta_pve_tags` might be useful to build more complex configurations in Prometheus. As an example, an `alert` tag can be extracted to dine alerting routes based on the tag value.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
Extract `group` and `alert` from a list of tags like this: `__meta_pve_tags="alert_team-1,group_cluster-1,node_node-1"`
|
||||||
|
|
||||||
|
```YAML
|
||||||
|
|
||||||
|
relabel_configs:
|
||||||
|
- source_labels:
|
||||||
|
- __meta_pve_tags
|
||||||
|
regex: ".*group_([\w\-_]*)"
|
||||||
|
target_label: "group"
|
||||||
|
replacement: "${1}"
|
||||||
|
- source_labels:
|
||||||
|
- __meta_pve_tags
|
||||||
|
regex: ".*alert_([\w\-_]*)"
|
||||||
|
target_label: "alert"
|
||||||
|
replacement: "${1}"
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the extracted `alert` label to set an Alertmanager route:
|
||||||
|
|
||||||
|
```YAML
|
||||||
|
routes:
|
||||||
|
- receiver: "empty"
|
||||||
|
matchers:
|
||||||
|
- alert = muted
|
||||||
|
- receiver: "team-1"
|
||||||
|
matchers:
|
||||||
|
- alert = team-1
|
||||||
|
```
|
83
docs/content/usage/getting-started.md
Normal file
83
docs/content/usage/getting-started.md
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
---
|
||||||
|
title: Getting Started
|
||||||
|
---
|
||||||
|
|
||||||
|
{{< toc >}}
|
||||||
|
|
||||||
|
## Available Labels
|
||||||
|
|
||||||
|
The following list of meta labels can be used to relabel your scrape results:
|
||||||
|
|
||||||
|
`__meta_pve_ipv4`
|
||||||
|
: Discovered IPv4 address or `False` if not found. To discover the IP address either QEMU guest agent or a cloud-init configuration is required.
|
||||||
|
|
||||||
|
`__meta_pve_ipv6`
|
||||||
|
: Discovered IPv6 address or `False` if not found. To discover the IP address either QEMU guest agent or a cloud-init configuration is required.
|
||||||
|
|
||||||
|
`__meta_pve_name`
|
||||||
|
: Name of the node.
|
||||||
|
|
||||||
|
`__meta_pve_type`
|
||||||
|
: Node type, either `qemu` or `lxc`.
|
||||||
|
|
||||||
|
`__meta_pve_vmid`
|
||||||
|
: VMID of the node.
|
||||||
|
|
||||||
|
`__meta_pve_cpu`
|
||||||
|
: Current CPU load of the node.
|
||||||
|
|
||||||
|
`__meta_pve_cores`
|
||||||
|
: Assigned CPU cores for the node.
|
||||||
|
|
||||||
|
`__meta_pve_memory`
|
||||||
|
: Assigned RAM for the node.
|
||||||
|
|
||||||
|
`__meta_pve_status`
|
||||||
|
: Current state of the node.
|
||||||
|
|
||||||
|
`__meta_pve_tags`
|
||||||
|
: A comma-separated list of tags, as set on the node. The label is not getting exported if no tags were found. (Requires PVE 6+)
|
||||||
|
|
||||||
|
`__meta_pve_groups`
|
||||||
|
: Groups discovered from the `Notes` field of the node. Need to be a valid JSON string e.g. `{"groups":["group1","group2"]}`.
|
||||||
|
|
||||||
|
## Prometheus configuration
|
||||||
|
|
||||||
|
### File service discovery
|
||||||
|
|
||||||
|
Prometheus needs a basic file service discovery configuration to fetch system metrics from the host's discovered from PVE. Depending on the used metrics exporter the configuration need to be adjusted, using [Telegraf](https://github.com/influxdata/telegraf/) a starter configuration might look like this:
|
||||||
|
|
||||||
|
```YAML
|
||||||
|
- file_sd_configs:
|
||||||
|
- files:
|
||||||
|
- /opt/prometheus/conf/file_sd/proxmox.json
|
||||||
|
job_name: telegraf-pve
|
||||||
|
metrics_path: /metrics
|
||||||
|
relabel_configs:
|
||||||
|
- replacement: ${1}:9273
|
||||||
|
source_labels:
|
||||||
|
- __meta_pve_name
|
||||||
|
target_label: __address__
|
||||||
|
- source_labels:
|
||||||
|
- __meta_pve_name
|
||||||
|
target_label: instance
|
||||||
|
```
|
||||||
|
|
||||||
|
### HTTP service discovery
|
||||||
|
|
||||||
|
If the static file is served by a web server, e.g. while using the [Prometheus Operator](/setup/prometheus-operator/) setup, a HTTP service discovery configuration is required:
|
||||||
|
|
||||||
|
```YAML
|
||||||
|
- http_sd_configs:
|
||||||
|
- url: http://pve-sd-service:80/proxmox.json
|
||||||
|
job_name: telegraf-pve
|
||||||
|
metrics_path: /metrics
|
||||||
|
relabel_configs:
|
||||||
|
- replacement: ${1}:9273
|
||||||
|
source_labels:
|
||||||
|
- __meta_pve_name
|
||||||
|
target_label: __address__
|
||||||
|
- source_labels:
|
||||||
|
- __meta_pve_name
|
||||||
|
target_label: instance
|
||||||
|
```
|
|
@ -2,10 +2,12 @@
|
||||||
main:
|
main:
|
||||||
- name: Setup
|
- name: Setup
|
||||||
sub:
|
sub:
|
||||||
- name: Using pip
|
- name: Using PIP
|
||||||
ref: "/setup/pip"
|
ref: "/setup/pip"
|
||||||
- name: Using docker
|
- name: Using Docker
|
||||||
ref: "/setup/docker"
|
ref: "/setup/docker"
|
||||||
|
- name: Using Prometheus Operator
|
||||||
|
ref: "/setup/prometheus-operator"
|
||||||
- name: Configuration
|
- name: Configuration
|
||||||
ref: "/configuration"
|
ref: "/configuration"
|
||||||
sub:
|
sub:
|
||||||
|
@ -16,4 +18,8 @@ main:
|
||||||
- name: Environment variables
|
- name: Environment variables
|
||||||
ref: "/configuration/env"
|
ref: "/configuration/env"
|
||||||
- name: Usage
|
- name: Usage
|
||||||
ref: "/usage"
|
sub:
|
||||||
|
- name: Getting Started
|
||||||
|
ref: "/usage/getting-started"
|
||||||
|
- name: Advanced
|
||||||
|
ref: "/usage/advanced"
|
||||||
|
|
162
docs/static/socialmedia.svg
vendored
Normal file
162
docs/static/socialmedia.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 20 KiB |
BIN
docs/static/socialmedia2.png
vendored
BIN
docs/static/socialmedia2.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 32 KiB |
1471
poetry.lock
generated
1471
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
0
prometheuspvesd/.drone.yml
Normal file
0
prometheuspvesd/.drone.yml
Normal file
|
@ -6,6 +6,7 @@ import json
|
||||||
import shutil
|
import shutil
|
||||||
import signal
|
import signal
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from os import chmod
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from prometheus_client import start_http_server
|
from prometheus_client import start_http_server
|
||||||
|
@ -36,11 +37,9 @@ class PrometheusSD:
|
||||||
self.discovery = Discovery()
|
self.discovery = Discovery()
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
if not self.config.config["service"]:
|
if not self.config.config["service"]:
|
||||||
self.log.sysexit_with_message(
|
self.log.sysexit_with_message(f"Proxmoxer API error: {str(e).strip()}")
|
||||||
"Proxmoxer API error: {0}".format(str(e).strip())
|
|
||||||
)
|
|
||||||
|
|
||||||
self.logger.error("Proxmoxer API error: {0}".format(str(e).strip()))
|
self.logger.error(f"Proxmoxer API error: {str(e).strip()}")
|
||||||
sleep(60)
|
sleep(60)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -60,25 +59,28 @@ class PrometheusSD:
|
||||||
"--config",
|
"--config",
|
||||||
dest="config_file",
|
dest="config_file",
|
||||||
action="store",
|
action="store",
|
||||||
help="location of configuration file"
|
help="location of configuration file",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-o", "--output", dest="output_file", action="store", help="output file"
|
"-o", "--output", dest="output_file", action="store", help="output file"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-m", "--mode", dest="output_file_mode", action="store", help="output file mode"
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-d",
|
"-d",
|
||||||
"--loop-delay",
|
"--loop-delay",
|
||||||
dest="loop_delay",
|
dest="loop_delay",
|
||||||
action="store",
|
action="store",
|
||||||
type=int,
|
type=int,
|
||||||
help="delay between discovery runs"
|
help="delay between discovery runs",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--no-service",
|
"--no-service",
|
||||||
dest="service",
|
dest="service",
|
||||||
action="store_false",
|
action="store_false",
|
||||||
default=None,
|
default=None,
|
||||||
help="run discovery only once"
|
help="run discovery only once",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-f",
|
"-f",
|
||||||
|
@ -86,7 +88,7 @@ class PrometheusSD:
|
||||||
dest="logging.format",
|
dest="logging.format",
|
||||||
metavar="LOG_FORMAT",
|
metavar="LOG_FORMAT",
|
||||||
action="store",
|
action="store",
|
||||||
help="used log format"
|
help="used log format",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v", dest="logging.level", action="append_const", const=-1, help="increase log level"
|
"-v", dest="logging.level", action="append_const", const=-1, help="increase log level"
|
||||||
|
@ -94,9 +96,7 @@ class PrometheusSD:
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-q", dest="logging.level", action="append_const", const=1, help="decrease log level"
|
"-q", dest="logging.level", action="append_const", const=1, help="decrease log level"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
||||||
"--version", action="version", version="%(prog)s {}".format(__version__)
|
|
||||||
)
|
|
||||||
|
|
||||||
return parser.parse_args().__dict__
|
return parser.parse_args().__dict__
|
||||||
|
|
||||||
|
@ -111,16 +111,25 @@ class PrometheusSD:
|
||||||
config.config["logging"]["level"], config.config["logging"]["format"]
|
config.config["logging"]["level"], config.config["logging"]["format"]
|
||||||
)
|
)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
self.log.sysexit_with_message("Can not set log level.\n{}".format(str(e)))
|
self.log.sysexit_with_message(f"Can not set log level.\n{e!s}")
|
||||||
|
|
||||||
required = [("pve.server", config.config["pve"]["server"]),
|
required = [
|
||||||
("pve.user", config.config["pve"]["user"]),
|
("pve.server", config.config["pve"]["server"]),
|
||||||
("pve.password", config.config["pve"]["password"])]
|
("pve.user", config.config["pve"]["user"]),
|
||||||
|
]
|
||||||
for name, value in required:
|
for name, value in required:
|
||||||
if not value:
|
if not value:
|
||||||
self.log.sysexit_with_message("Option '{}' is required but not set".format(name))
|
self.log.sysexit_with_message(f"Option '{name}' is required but not set")
|
||||||
|
|
||||||
self.logger.info("Using config file {}".format(config.config_file))
|
if not config.config["pve"]["password"] and not (
|
||||||
|
config.config["pve"]["token_name"] and config.config["pve"]["token_value"]
|
||||||
|
):
|
||||||
|
self.log.sysexit_with_message(
|
||||||
|
"Either 'pve.password' or 'pve.token_name' and 'pve.token_value' "
|
||||||
|
"are required but not set"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.logger.info(f"Using config file {config.config_file}")
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
@ -136,16 +145,16 @@ class PrometheusSD:
|
||||||
)
|
)
|
||||||
start_http_server(
|
start_http_server(
|
||||||
self.config.config["metrics"]["port"],
|
self.config.config["metrics"]["port"],
|
||||||
addr=self.config.config["metrics"]["address"]
|
addr=self.config.config["metrics"]["address"],
|
||||||
)
|
)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
inventory = self.discovery.propagate()
|
inventory = self.discovery.propagate()
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
self.logger.error("Proxmoxer API error: {0}".format(str(e).strip()))
|
self.logger.error(f"Proxmoxer API error: {str(e).strip()}")
|
||||||
except Exception as e: # noqa
|
except Exception as e: # noqa
|
||||||
self.logger.error("Unknown error: {0}".format(str(e).strip()))
|
self.logger.error(f"Unknown error: {str(e).strip()}")
|
||||||
else:
|
else:
|
||||||
self._write(inventory)
|
self._write(inventory)
|
||||||
|
|
||||||
|
@ -170,8 +179,9 @@ class PrometheusSD:
|
||||||
json.dump(output, tf, indent=4)
|
json.dump(output, tf, indent=4)
|
||||||
|
|
||||||
shutil.move(temp_file.name, self.config.config["output_file"])
|
shutil.move(temp_file.name, self.config.config["output_file"])
|
||||||
|
chmod(self.config.config["output_file"], int(self.config.config["output_file_mode"], 8))
|
||||||
|
|
||||||
def _terminate(self, signal, frame):
|
def _terminate(self, signal, frame): # noqa
|
||||||
self.log.sysexit_with_message("Terminating", code=0)
|
self.log.sysexit_with_message("Terminating", code=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
105
prometheuspvesd/client.py
Normal file
105
prometheuspvesd/client.py
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
"""Proxmox Client."""
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from prometheus_client import Counter
|
||||||
|
|
||||||
|
from prometheuspvesd.config import SingleConfig
|
||||||
|
from prometheuspvesd.exception import APIError
|
||||||
|
from prometheuspvesd.logger import SingleLog
|
||||||
|
from prometheuspvesd.model import HostList
|
||||||
|
from prometheuspvesd.utils import to_bool
|
||||||
|
|
||||||
|
try:
|
||||||
|
from proxmoxer import ProxmoxAPI
|
||||||
|
|
||||||
|
HAS_PROXMOXER = True
|
||||||
|
except ImportError:
|
||||||
|
HAS_PROXMOXER = False
|
||||||
|
|
||||||
|
PVE_REQUEST_COUNT_TOTAL = Counter("pve_sd_requests_total", "Total count of requests to PVE API")
|
||||||
|
PVE_REQUEST_COUNT_ERROR_TOTAL = Counter(
|
||||||
|
"pve_sd_requests_error_total", "Total count of failed requests to PVE API"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ProxmoxClient:
|
||||||
|
"""Proxmox API Client."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
if not HAS_PROXMOXER:
|
||||||
|
self.log.sysexit_with_message(
|
||||||
|
"The Proxmox VE Prometheus SD requires proxmoxer: "
|
||||||
|
"https://pypi.org/project/proxmoxer/"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.config = SingleConfig()
|
||||||
|
self.log = SingleLog()
|
||||||
|
self.logger = SingleLog().logger
|
||||||
|
self.client = self._auth()
|
||||||
|
self.logger.debug("Successfully authenticated")
|
||||||
|
self.host_list = HostList()
|
||||||
|
|
||||||
|
def _auth(self):
|
||||||
|
try:
|
||||||
|
self.logger.debug(
|
||||||
|
"Trying to authenticate against {} as user {}".format(
|
||||||
|
self.config.config["pve"]["server"], self.config.config["pve"]["user"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.config.config["pve"]["token_name"]:
|
||||||
|
self.logger.debug("Using token login")
|
||||||
|
return ProxmoxAPI(
|
||||||
|
self.config.config["pve"]["server"],
|
||||||
|
user=self.config.config["pve"]["user"],
|
||||||
|
token_name=self.config.config["pve"]["token_name"],
|
||||||
|
token_value=self.config.config["pve"]["token_value"],
|
||||||
|
verify_ssl=to_bool(self.config.config["pve"]["verify_ssl"]),
|
||||||
|
timeout=self.config.config["pve"]["auth_timeout"],
|
||||||
|
)
|
||||||
|
|
||||||
|
return ProxmoxAPI(
|
||||||
|
self.config.config["pve"]["server"],
|
||||||
|
user=self.config.config["pve"]["user"],
|
||||||
|
password=self.config.config["pve"]["password"],
|
||||||
|
verify_ssl=to_bool(self.config.config["pve"]["verify_ssl"]),
|
||||||
|
timeout=self.config.config["pve"]["auth_timeout"],
|
||||||
|
)
|
||||||
|
except requests.RequestException as e:
|
||||||
|
PVE_REQUEST_COUNT_ERROR_TOTAL.inc()
|
||||||
|
raise APIError(str(e)) from e
|
||||||
|
|
||||||
|
def _do_request(self, *args):
|
||||||
|
PVE_REQUEST_COUNT_TOTAL.inc()
|
||||||
|
try:
|
||||||
|
# create a new tuple containing nodes and unpack it again for client.get
|
||||||
|
return self.client.get(*("nodes", *args))
|
||||||
|
except requests.RequestException as e:
|
||||||
|
PVE_REQUEST_COUNT_ERROR_TOTAL.inc()
|
||||||
|
raise APIError(str(e)) from e
|
||||||
|
|
||||||
|
def get_nodes(self):
|
||||||
|
self.logger.debug("fetching all nodes")
|
||||||
|
return self._do_request()
|
||||||
|
|
||||||
|
def get_all_vms(self, pve_node):
|
||||||
|
self.logger.debug(f"fetching all vms on node {pve_node}")
|
||||||
|
return self._do_request(pve_node, "qemu")
|
||||||
|
|
||||||
|
def get_all_containers(self, pve_node):
|
||||||
|
self.logger.debug(f"fetching all containers on node {pve_node}")
|
||||||
|
return self._do_request(pve_node, "lxc")
|
||||||
|
|
||||||
|
def get_instance_config(self, pve_node, pve_type, vmid):
|
||||||
|
self.logger.debug(f"fetching instance config for {vmid} on {pve_node}")
|
||||||
|
return self._do_request(pve_node, pve_type, vmid, "config")
|
||||||
|
|
||||||
|
def get_agent_info(self, pve_node, pve_type, vmid):
|
||||||
|
self.logger.debug(f"fetching agent info for {vmid} on {pve_node}")
|
||||||
|
return self._do_request(pve_node, pve_type, vmid, "agent", "info")["result"]
|
||||||
|
|
||||||
|
def get_network_interfaces(self, pve_node, vmid):
|
||||||
|
self.logger.debug(f"fetching network interfaces for {vmid} on {pve_node}")
|
||||||
|
return self._do_request(pve_node, "qemu", vmid, "agent", "network-get-interfaces")[
|
||||||
|
"result"
|
||||||
|
]
|
|
@ -2,8 +2,7 @@
|
||||||
"""Global settings definition."""
|
"""Global settings definition."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path, PurePath
|
||||||
from pathlib import PurePath
|
|
||||||
|
|
||||||
import anyconfig
|
import anyconfig
|
||||||
import environs
|
import environs
|
||||||
|
@ -21,7 +20,7 @@ cache_dir = AppDirs("prometheus-pve-sd").user_cache_dir
|
||||||
default_output_file = os.path.join(cache_dir, "pve.json")
|
default_output_file = os.path.join(cache_dir, "pve.json")
|
||||||
|
|
||||||
|
|
||||||
class Config():
|
class Config:
|
||||||
"""
|
"""
|
||||||
Create an object with all necessary settings.
|
Create an object with all necessary settings.
|
||||||
|
|
||||||
|
@ -35,98 +34,134 @@ class Config():
|
||||||
"metrics.enabled": {
|
"metrics.enabled": {
|
||||||
"default": True,
|
"default": True,
|
||||||
"env": "METRICS_ENABLED",
|
"env": "METRICS_ENABLED",
|
||||||
"type": environs.Env().bool
|
"type": environs.Env().bool,
|
||||||
},
|
},
|
||||||
"metrics.address": {
|
"metrics.address": {
|
||||||
"default": "127.0.0.1",
|
"default": "127.0.0.1",
|
||||||
"env": "METRICS_ADDRESS",
|
"env": "METRICS_ADDRESS",
|
||||||
"type": environs.Env().str
|
"type": environs.Env().str,
|
||||||
},
|
},
|
||||||
"metrics.port": {
|
"metrics.port": {
|
||||||
"default": 8000,
|
"default": 8000,
|
||||||
"env": "METRICS_PORT",
|
"env": "METRICS_PORT",
|
||||||
"type": environs.Env().int
|
"type": environs.Env().int,
|
||||||
},
|
},
|
||||||
"config_file": {
|
"config_file": {
|
||||||
"default": "",
|
"default": "",
|
||||||
"env": "CONFIG_FILE",
|
"env": "CONFIG_FILE",
|
||||||
"type": environs.Env().str
|
"type": environs.Env().str,
|
||||||
},
|
},
|
||||||
"logging.level": {
|
"logging.level": {
|
||||||
"default": "WARNING",
|
"default": "WARNING",
|
||||||
"env": "LOG_LEVEL",
|
"env": "LOG_LEVEL",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().str
|
"type": environs.Env().str,
|
||||||
},
|
},
|
||||||
"logging.format": {
|
"logging.format": {
|
||||||
"default": "console",
|
"default": "console",
|
||||||
"env": "LOG_FORMAT",
|
"env": "LOG_FORMAT",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().str
|
"type": environs.Env().str,
|
||||||
},
|
},
|
||||||
"output_file": {
|
"output_file": {
|
||||||
"default": default_output_file,
|
"default": default_output_file,
|
||||||
"env": "OUTPUT_FILE",
|
"env": "OUTPUT_FILE",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().str
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"output_file_mode": {
|
||||||
|
"default": "0640",
|
||||||
|
"env": "OUTPUT_FILE_MODE",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
},
|
},
|
||||||
"loop_delay": {
|
"loop_delay": {
|
||||||
"default": 300,
|
"default": 300,
|
||||||
"env": "LOOP_DELAY",
|
"env": "LOOP_DELAY",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().int
|
"type": environs.Env().int,
|
||||||
},
|
},
|
||||||
"service": {
|
"service": {
|
||||||
"default": True,
|
"default": True,
|
||||||
"env": "SERVICE",
|
"env": "SERVICE",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().bool
|
"type": environs.Env().bool,
|
||||||
},
|
},
|
||||||
"exclude_state": {
|
"exclude_state": {
|
||||||
"default": [],
|
"default": [],
|
||||||
"env": "EXCLUDE_STATE",
|
"env": "EXCLUDE_STATE",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().list
|
"type": environs.Env().list,
|
||||||
},
|
},
|
||||||
"exclude_vmid": {
|
"exclude_vmid": {
|
||||||
"default": [],
|
"default": [],
|
||||||
"env": "EXCLUDE_VMID",
|
"env": "EXCLUDE_VMID",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().list
|
"type": environs.Env().list,
|
||||||
|
},
|
||||||
|
"include_vmid": {
|
||||||
|
"default": [],
|
||||||
|
"env": "INCLUDE_VMID",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().list,
|
||||||
|
},
|
||||||
|
"exclude_tags": {
|
||||||
|
"default": [],
|
||||||
|
"env": "EXCLUDE_TAGS",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().list,
|
||||||
|
},
|
||||||
|
"include_tags": {
|
||||||
|
"default": [],
|
||||||
|
"env": "INCLUDE_TAGS",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().list,
|
||||||
},
|
},
|
||||||
"pve.server": {
|
"pve.server": {
|
||||||
"default": "",
|
"default": "",
|
||||||
"env": "PVE_SERVER",
|
"env": "PVE_SERVER",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().str
|
"type": environs.Env().str,
|
||||||
},
|
},
|
||||||
"pve.user": {
|
"pve.user": {
|
||||||
"default": "",
|
"default": "",
|
||||||
"env": "PVE_USER",
|
"env": "PVE_USER",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().str
|
"type": environs.Env().str,
|
||||||
},
|
},
|
||||||
"pve.password": {
|
"pve.password": {
|
||||||
"default": "",
|
"default": "",
|
||||||
"env": "PVE_PASSWORD",
|
"env": "PVE_PASSWORD",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().str
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"pve.token_name": {
|
||||||
|
"default": "",
|
||||||
|
"env": "PVE_TOKEN_NAME",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"pve.token_value": {
|
||||||
|
"default": "",
|
||||||
|
"env": "PVE_TOKEN_VALUE",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
},
|
},
|
||||||
"pve.auth_timeout": {
|
"pve.auth_timeout": {
|
||||||
"default": 5,
|
"default": 5,
|
||||||
"env": "PVE_AUTH_TIMEOUT",
|
"env": "PVE_AUTH_TIMEOUT",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().int
|
"type": environs.Env().int,
|
||||||
},
|
},
|
||||||
"pve.verify_ssl": {
|
"pve.verify_ssl": {
|
||||||
"default": True,
|
"default": True,
|
||||||
"env": "PVE_VERIFY_SSL",
|
"env": "PVE_VERIFY_SSL",
|
||||||
"file": True,
|
"file": True,
|
||||||
"type": environs.Env().bool
|
"type": environs.Env().bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, args={}):
|
def __init__(self, args=None):
|
||||||
"""
|
"""
|
||||||
Initialize a new settings class.
|
Initialize a new settings class.
|
||||||
|
|
||||||
|
@ -135,7 +170,10 @@ class Config():
|
||||||
:returns: None
|
:returns: None
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self._args = args
|
if args is None:
|
||||||
|
self._args = {}
|
||||||
|
else:
|
||||||
|
self._args = args
|
||||||
self._schema = None
|
self._schema = None
|
||||||
self.config_file = default_config_file
|
self.config_file = default_config_file
|
||||||
self.config = None
|
self.config = None
|
||||||
|
@ -176,12 +214,12 @@ class Config():
|
||||||
value = item["type"](envname)
|
value = item["type"](envname)
|
||||||
normalized = self._add_dict_branch(normalized, key.split("."), value)
|
normalized = self._add_dict_branch(normalized, key.split("."), value)
|
||||||
except environs.EnvError as e:
|
except environs.EnvError as e:
|
||||||
if '"{}" not set'.format(envname) in str(e):
|
if f'"{envname}" not set' in str(e):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise prometheuspvesd.exception.ConfigError(
|
raise prometheuspvesd.exception.ConfigError(
|
||||||
"Unable to read environment variable", str(e)
|
"Unable to read environment variable", str(e)
|
||||||
)
|
) from e
|
||||||
|
|
||||||
return normalized
|
return normalized
|
||||||
|
|
||||||
|
@ -202,17 +240,18 @@ class Config():
|
||||||
|
|
||||||
for config in source_files:
|
for config in source_files:
|
||||||
if config and os.path.exists(config):
|
if config and os.path.exists(config):
|
||||||
with open(config, "r", encoding="utf8") as stream:
|
with open(config, encoding="utf8") as stream:
|
||||||
s = stream.read()
|
s = stream.read()
|
||||||
try:
|
try:
|
||||||
file_dict = ruamel.yaml.safe_load(s)
|
file_dict = ruamel.yaml.YAML(typ="safe", pure=True).load(s)
|
||||||
except (
|
except (
|
||||||
ruamel.yaml.composer.ComposerError, ruamel.yaml.scanner.ScannerError
|
ruamel.yaml.composer.ComposerError,
|
||||||
|
ruamel.yaml.scanner.ScannerError,
|
||||||
) as e:
|
) as e:
|
||||||
message = "{} {}".format(e.context, e.problem)
|
message = f"{e.context} {e.problem}"
|
||||||
raise prometheuspvesd.exception.ConfigError(
|
raise prometheuspvesd.exception.ConfigError(
|
||||||
"Unable to read config file {}".format(config), message
|
f"Unable to read config file {config}", message
|
||||||
)
|
) from e
|
||||||
|
|
||||||
if self._validate(file_dict):
|
if self._validate(file_dict):
|
||||||
anyconfig.merge(defaults, file_dict, ac_merge=anyconfig.MS_DICTS)
|
anyconfig.merge(defaults, file_dict, ac_merge=anyconfig.MS_DICTS)
|
||||||
|
@ -239,27 +278,26 @@ class Config():
|
||||||
if not os.path.isabs(path):
|
if not os.path.isabs(path):
|
||||||
base = os.path.join(os.getcwd(), path)
|
base = os.path.join(os.getcwd(), path)
|
||||||
return os.path.abspath(os.path.expanduser(os.path.expandvars(base)))
|
return os.path.abspath(os.path.expanduser(os.path.expandvars(base)))
|
||||||
else:
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def _validate(self, config):
|
def _validate(self, config):
|
||||||
try:
|
try:
|
||||||
anyconfig.validate(config, self.schema, ac_schema_safe=False)
|
anyconfig.validate(config, self.schema, ac_schema_safe=False)
|
||||||
except jsonschema.exceptions.ValidationError as e:
|
except jsonschema.exceptions.ValidationError as e:
|
||||||
schema_error = "Failed validating '{validator}' in schema{schema}\n{message}".format(
|
schema = format_as_index(list(e.relative_schema_path)[:-1], 0)
|
||||||
validator=e.validator,
|
schema_error = f"Failed validating '{e.validator}' in schema {schema}\n{e.message}"
|
||||||
schema=format_as_index(list(e.relative_schema_path)[:-1]),
|
raise prometheuspvesd.exception.ConfigError("Configuration error", schema_error) from e
|
||||||
message=e.message
|
|
||||||
)
|
|
||||||
raise prometheuspvesd.exception.ConfigError("Configuration error", schema_error)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _add_dict_branch(self, tree, vector, value):
|
def _add_dict_branch(self, tree, vector, value):
|
||||||
key = vector[0]
|
key = vector[0]
|
||||||
tree[key] = value \
|
tree[key] = (
|
||||||
if len(vector) == 1 \
|
value
|
||||||
else self._add_dict_branch(tree[key] if key in tree else {}, vector[1:], value)
|
if len(vector) == 1
|
||||||
|
else self._add_dict_branch(tree.get(key, {}), vector[1:], value)
|
||||||
|
)
|
||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,63 +6,30 @@ import json
|
||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
import requests
|
from prometheus_client import Gauge, Summary
|
||||||
from prometheus_client import Counter
|
|
||||||
from prometheus_client import Gauge
|
|
||||||
from prometheus_client import Summary
|
|
||||||
|
|
||||||
|
from prometheuspvesd.client import ProxmoxClient
|
||||||
from prometheuspvesd.config import SingleConfig
|
from prometheuspvesd.config import SingleConfig
|
||||||
from prometheuspvesd.exception import APIError
|
from prometheuspvesd.exception import APIError
|
||||||
from prometheuspvesd.logger import SingleLog
|
from prometheuspvesd.logger import SingleLog
|
||||||
from prometheuspvesd.model import Host
|
from prometheuspvesd.model import Host, HostList
|
||||||
from prometheuspvesd.model import HostList
|
|
||||||
from prometheuspvesd.utils import to_bool
|
|
||||||
|
|
||||||
try:
|
|
||||||
from proxmoxer import ProxmoxAPI
|
|
||||||
HAS_PROXMOXER = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_PROXMOXER = False
|
|
||||||
|
|
||||||
PROPAGATION_TIME = Summary(
|
PROPAGATION_TIME = Summary(
|
||||||
"pve_sd_propagate_seconds", "Time spent propagating the inventory from PVE"
|
"pve_sd_propagate_seconds", "Time spent propagating the inventory from PVE"
|
||||||
)
|
)
|
||||||
HOST_GAUGE = Gauge("pve_sd_hosts", "Number of hosts discovered by PVE SD")
|
HOST_GAUGE = Gauge("pve_sd_hosts", "Number of hosts discovered by PVE SD")
|
||||||
PVE_REQUEST_COUNT_TOTAL = Counter("pve_sd_requests_total", "Total count of requests to PVE API")
|
|
||||||
PVE_REQUEST_COUNT_ERROR_TOTAL = Counter(
|
|
||||||
"pve_sd_requests_error_total", "Total count of failed requests to PVE API"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Discovery():
|
class Discovery:
|
||||||
"""Prometheus PVE Service Discovery."""
|
"""Prometheus PVE Service Discovery."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if not HAS_PROXMOXER:
|
|
||||||
self.log.sysexit_with_message(
|
|
||||||
"The Proxmox VE Prometheus SD requires proxmoxer: "
|
|
||||||
"https://pypi.org/project/proxmoxer/"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.config = SingleConfig()
|
self.config = SingleConfig()
|
||||||
self.log = SingleLog()
|
self.log = SingleLog()
|
||||||
self.logger = SingleLog().logger
|
self.logger = SingleLog().logger
|
||||||
self.client = self._auth()
|
self.client = ProxmoxClient()
|
||||||
self.host_list = HostList()
|
self.host_list = HostList()
|
||||||
|
|
||||||
def _auth(self):
|
|
||||||
try:
|
|
||||||
return ProxmoxAPI(
|
|
||||||
self.config.config["pve"]["server"],
|
|
||||||
user=self.config.config["pve"]["user"],
|
|
||||||
password=self.config.config["pve"]["password"],
|
|
||||||
verify_ssl=to_bool(self.config.config["pve"]["verify_ssl"]),
|
|
||||||
timeout=self.config.config["pve"]["auth_timeout"]
|
|
||||||
)
|
|
||||||
except requests.RequestException as e:
|
|
||||||
PVE_REQUEST_COUNT_ERROR_TOTAL.inc()
|
|
||||||
raise APIError(str(e))
|
|
||||||
|
|
||||||
def _get_names(self, pve_list, pve_type):
|
def _get_names(self, pve_list, pve_type):
|
||||||
names = []
|
names = []
|
||||||
|
|
||||||
|
@ -92,27 +59,23 @@ class Discovery():
|
||||||
if pve_type == "qemu":
|
if pve_type == "qemu":
|
||||||
# If qemu agent is enabled, try to gather the IP address
|
# If qemu agent is enabled, try to gather the IP address
|
||||||
try:
|
try:
|
||||||
PVE_REQUEST_COUNT_TOTAL.inc()
|
if self.client.get_agent_info(pve_node, pve_type, vmid) is not None:
|
||||||
if self.client.get("nodes", pve_node, pve_type, vmid, "agent", "info") is not None:
|
networks = self.client.get_network_interfaces(pve_node, vmid)
|
||||||
networks = self.client.get(
|
except Exception: # noqa
|
||||||
"nodes", pve_node, "qemu", vmid, "agent", "network-get-interfaces"
|
|
||||||
)["result"]
|
|
||||||
except Exception: # noqa # nosec
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if type(networks) is list:
|
if isinstance(networks, list):
|
||||||
for network in networks:
|
for network in networks:
|
||||||
for ip_address in network["ip-addresses"]:
|
for ip_address in network.get("ip-addresses", []):
|
||||||
if ip_address["ip-address-type"] == "ipv4" and not ipv4_address:
|
if ip_address["ip-address-type"] == "ipv4" and not ipv4_address:
|
||||||
ipv4_address = self._validate_ip(ip_address["ip-address"])
|
ipv4_address = self._validate_ip(ip_address["ip-address"])
|
||||||
elif ip_address["ip-address-type"] == "ipv6" and not ipv6_address:
|
elif ip_address["ip-address-type"] == "ipv6" and not ipv6_address:
|
||||||
ipv6_address = self._validate_ip(ip_address["ip-address"])
|
ipv6_address = self._validate_ip(ip_address["ip-address"])
|
||||||
|
|
||||||
if not ipv4_address:
|
config = self.client.get_instance_config(pve_node, pve_type, vmid)
|
||||||
|
if config and not ipv4_address:
|
||||||
try:
|
try:
|
||||||
PVE_REQUEST_COUNT_TOTAL.inc()
|
if "ipconfig0" in config:
|
||||||
config = self.client.get("nodes", pve_node, pve_type, vmid, "config")
|
|
||||||
if "ipconfig0" in config.keys():
|
|
||||||
sources = [config["net0"], config["ipconfig0"]]
|
sources = [config["net0"], config["ipconfig0"]]
|
||||||
else:
|
else:
|
||||||
sources = [config["net0"]]
|
sources = [config["net0"]]
|
||||||
|
@ -122,32 +85,51 @@ class Discovery():
|
||||||
if find and find.group(1):
|
if find and find.group(1):
|
||||||
ipv4_address = find.group(1)
|
ipv4_address = find.group(1)
|
||||||
break
|
break
|
||||||
except Exception: # noqa # nosec
|
except Exception: # noqa
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not ipv6_address:
|
if config and not ipv6_address:
|
||||||
try:
|
try:
|
||||||
PVE_REQUEST_COUNT_TOTAL.inc()
|
if "ipconfig0" in config:
|
||||||
config = self.client.get("nodes", pve_node, pve_type, vmid, "config")
|
|
||||||
if "ipconfig0" in config.keys():
|
|
||||||
sources = [config["net0"], config["ipconfig0"]]
|
sources = [config["net0"], config["ipconfig0"]]
|
||||||
else:
|
else:
|
||||||
sources = [config["net0"]]
|
sources = [config["net0"]]
|
||||||
|
|
||||||
for s in sources:
|
for s in sources:
|
||||||
find = re.search(r"ip=(\d*:\d*:\d*:\d*:\d*:\d*)", str(s))
|
find = re.search(
|
||||||
|
r"ip=(([a-fA-F0-9]{0,4}:{0,2}){0,7}:[0-9a-fA-F]{1,4})", str(s)
|
||||||
|
)
|
||||||
if find and find.group(1):
|
if find and find.group(1):
|
||||||
ipv6_address = find.group(1)
|
ipv6_address = find.group(1)
|
||||||
break
|
break
|
||||||
except Exception: # noqa # nosec
|
except Exception: # noqa
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return ipv4_address, ipv6_address
|
return ipv4_address, ipv6_address
|
||||||
|
|
||||||
def _exclude(self, pve_list):
|
def _filter(self, pve_list):
|
||||||
filtered = []
|
filtered = []
|
||||||
for item in pve_list:
|
for item in pve_list:
|
||||||
obj = defaultdict(dict, item)
|
obj = defaultdict(dict, item)
|
||||||
|
tags = []
|
||||||
|
tags_excl = self.config.config["exclude_tags"]
|
||||||
|
|
||||||
|
if isinstance(obj["tags"], str):
|
||||||
|
tags = obj["tags"].split(";")
|
||||||
|
self.logger.debug(f"vmid {obj['vmid']}: discovered tags: {tags}")
|
||||||
|
|
||||||
|
if (
|
||||||
|
len(self.config.config["include_vmid"]) > 0
|
||||||
|
and str(obj["vmid"]) not in self.config.config["include_vmid"]
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if len(self.config.config["include_tags"]) > 0 and (
|
||||||
|
bool(obj["tags"]) is False # continue if tags is not set
|
||||||
|
or set(tags).isdisjoint(self.config.config["include_tags"])
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
if obj["template"] == 1:
|
if obj["template"] == 1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -157,6 +139,13 @@ class Discovery():
|
||||||
if str(obj["vmid"]) in self.config.config["exclude_vmid"]:
|
if str(obj["vmid"]) in self.config.config["exclude_vmid"]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if isinstance(obj["tags"], str) and not set(tags).isdisjoint(tags_excl):
|
||||||
|
self.logger.debug(
|
||||||
|
f"vmid {obj['vmid']}: "
|
||||||
|
f"excluded by tags: {list(set(tags).intersection(tags_excl))}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
filtered.append(item.copy())
|
filtered.append(item.copy())
|
||||||
return filtered
|
return filtered
|
||||||
|
|
||||||
|
@ -173,24 +162,21 @@ class Discovery():
|
||||||
@PROPAGATION_TIME.time()
|
@PROPAGATION_TIME.time()
|
||||||
def propagate(self):
|
def propagate(self):
|
||||||
self.host_list.clear()
|
self.host_list.clear()
|
||||||
|
nodelist = self._get_names(self.client.get_nodes(), "node")
|
||||||
PVE_REQUEST_COUNT_TOTAL.inc()
|
self.logger.info(f"Discovered nodes: {','.join(nodelist)}")
|
||||||
for node in self._get_names(self.client.get("nodes"), "node"):
|
for node in nodelist:
|
||||||
try:
|
try:
|
||||||
PVE_REQUEST_COUNT_TOTAL.inc()
|
qemu_list = self._filter(self.client.get_all_vms(node))
|
||||||
qemu_list = self._exclude(self.client.get("nodes", node, "qemu"))
|
container_list = self._filter(self.client.get_all_containers(node))
|
||||||
PVE_REQUEST_COUNT_TOTAL.inc()
|
except Exception as e:
|
||||||
container_list = self._exclude(self.client.get("nodes", node, "lxc"))
|
raise APIError(str(e)) from e
|
||||||
except Exception as e: # noqa
|
|
||||||
PVE_REQUEST_COUNT_ERROR_TOTAL.inc()
|
|
||||||
raise APIError(str(e))
|
|
||||||
|
|
||||||
# Merge QEMU and Containers lists from this node
|
# Merge QEMU and Containers lists from this node
|
||||||
instances = self._get_variables(qemu_list, "qemu").copy()
|
instances = self._get_variables(qemu_list, "qemu").copy()
|
||||||
instances.update(self._get_variables(container_list, "container"))
|
instances.update(self._get_variables(container_list, "container"))
|
||||||
|
|
||||||
HOST_GAUGE.set(len(instances))
|
HOST_GAUGE.set(len(instances))
|
||||||
self.logger.info("Found {} targets".format(len(instances)))
|
self.logger.info(f"{node}: Found {len(instances)} targets")
|
||||||
for host in instances:
|
for host in instances:
|
||||||
host_meta = instances[host]
|
host_meta = instances[host]
|
||||||
vmid = host_meta["proxmox_vmid"]
|
vmid = host_meta["proxmox_vmid"]
|
||||||
|
@ -200,16 +186,14 @@ class Discovery():
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pve_type = "qemu"
|
pve_type = "qemu"
|
||||||
|
|
||||||
PVE_REQUEST_COUNT_TOTAL.inc()
|
config = self.client.get_instance_config(node, pve_type, vmid)
|
||||||
config = self.client.get("nodes", node, pve_type, vmid, "config")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
description = (config["description"])
|
description = config["description"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
description = None
|
description = None
|
||||||
except Exception as e: # noqa
|
except Exception as e:
|
||||||
PVE_REQUEST_COUNT_ERROR_TOTAL.inc()
|
raise APIError(str(e)) from e
|
||||||
raise APIError(str(e))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
metadata = json.loads(description)
|
metadata = json.loads(description)
|
||||||
|
@ -223,7 +207,7 @@ class Discovery():
|
||||||
prom_host = Host(vmid, host, ipv4_address, ipv6_address, pve_type)
|
prom_host = Host(vmid, host, ipv4_address, ipv6_address, pve_type)
|
||||||
|
|
||||||
config_flags = [("cpu", "sockets"), ("cores", "cores"), ("memory", "memory")]
|
config_flags = [("cpu", "sockets"), ("cores", "cores"), ("memory", "memory")]
|
||||||
meta_flags = [("status", "proxmox_status")]
|
meta_flags = [("status", "proxmox_status"), ("tags", "proxmox_tags")]
|
||||||
|
|
||||||
for key, flag in config_flags:
|
for key, flag in config_flags:
|
||||||
if flag in config:
|
if flag in config:
|
||||||
|
@ -237,6 +221,6 @@ class Discovery():
|
||||||
prom_host.add_label("groups", ",".join(metadata["groups"]))
|
prom_host.add_label("groups", ",".join(metadata["groups"]))
|
||||||
|
|
||||||
self.host_list.add_host(prom_host)
|
self.host_list.add_host(prom_host)
|
||||||
self.logger.debug("Discovered {}".format(prom_host))
|
self.logger.debug(f"Discovered {prom_host}")
|
||||||
|
|
||||||
return self.host_list
|
return self.host_list
|
||||||
|
|
|
@ -3,11 +3,10 @@
|
||||||
|
|
||||||
|
|
||||||
class PrometheusSDError(Exception):
|
class PrometheusSDError(Exception):
|
||||||
"""Generic exception class for promtheus-pve-sd."""
|
"""Generic exception class for Prometheus-pve-sd."""
|
||||||
|
|
||||||
def __init__(self, msg, original_exception=""):
|
def __init__(self, msg, original_exception=""):
|
||||||
super(PrometheusSDError,
|
super().__init__(f"{msg}\n{original_exception}")
|
||||||
self).__init__("{msg}\n{org}".format(msg=msg, org=original_exception))
|
|
||||||
self.original_exception = original_exception
|
self.original_exception = original_exception
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,7 @@ import sys
|
||||||
import colorama
|
import colorama
|
||||||
from pythonjsonlogger import jsonlogger
|
from pythonjsonlogger import jsonlogger
|
||||||
|
|
||||||
from prometheuspvesd.utils import Singleton
|
from prometheuspvesd.utils import Singleton, to_bool
|
||||||
from prometheuspvesd.utils import to_bool
|
|
||||||
|
|
||||||
CONSOLE_FORMAT = "{}{}[%(levelname)s]{} %(message)s"
|
CONSOLE_FORMAT = "{}{}[%(levelname)s]{} %(message)s"
|
||||||
JSON_FORMAT = "%(asctime)s %(levelname)s %(message)s"
|
JSON_FORMAT = "%(asctime)s %(levelname)s %(message)s"
|
||||||
|
@ -26,7 +25,7 @@ def _should_do_markup():
|
||||||
colorama.init(autoreset=True, strip=not _should_do_markup())
|
colorama.init(autoreset=True, strip=not _should_do_markup())
|
||||||
|
|
||||||
|
|
||||||
class LogFilter(object):
|
class LogFilter:
|
||||||
"""A custom log filter which excludes log messages above the logged level."""
|
"""A custom log filter which excludes log messages above the logged level."""
|
||||||
|
|
||||||
def __init__(self, level):
|
def __init__(self, level):
|
||||||
|
@ -47,22 +46,22 @@ class LogFilter(object):
|
||||||
class SimpleFormatter(logging.Formatter):
|
class SimpleFormatter(logging.Formatter):
|
||||||
"""Logging Formatter for simple logs."""
|
"""Logging Formatter for simple logs."""
|
||||||
|
|
||||||
def format(self, record): # noqa
|
def format(self, record):
|
||||||
return logging.Formatter.format(self, record)
|
return logging.Formatter.format(self, record)
|
||||||
|
|
||||||
|
|
||||||
class MultilineFormatter(logging.Formatter):
|
class MultilineFormatter(logging.Formatter):
|
||||||
"""Logging Formatter to reset color after newline characters."""
|
"""Logging Formatter to reset color after newline characters."""
|
||||||
|
|
||||||
def format(self, record): # noqa
|
def format(self, record):
|
||||||
record.msg = record.msg.replace("\n", "\n{}... ".format(colorama.Style.RESET_ALL))
|
record.msg = record.msg.replace("\n", f"\n{colorama.Style.RESET_ALL}... ")
|
||||||
return logging.Formatter.format(self, record)
|
return logging.Formatter.format(self, record)
|
||||||
|
|
||||||
|
|
||||||
class MultilineJsonFormatter(jsonlogger.JsonFormatter):
|
class MultilineJsonFormatter(jsonlogger.JsonFormatter):
|
||||||
"""Logging Formatter to remove newline characters."""
|
"""Logging Formatter to remove newline characters."""
|
||||||
|
|
||||||
def format(self, record): # noqa
|
def format(self, record):
|
||||||
record.msg = record.msg.replace("\n", " ")
|
record.msg = record.msg.replace("\n", " ")
|
||||||
return jsonlogger.JsonFormatter.format(self, record)
|
return jsonlogger.JsonFormatter.format(self, record)
|
||||||
|
|
||||||
|
@ -70,11 +69,11 @@ class MultilineJsonFormatter(jsonlogger.JsonFormatter):
|
||||||
class Log:
|
class Log:
|
||||||
"""Handle logging."""
|
"""Handle logging."""
|
||||||
|
|
||||||
def __init__(self, level=logging.WARN, name="prometheuspvesd", log_format="console"):
|
def __init__(self, level=logging.WARNING, name="prometheuspvesd", log_format="console"):
|
||||||
self.logger = logging.getLogger(name)
|
self.logger = logging.getLogger(name)
|
||||||
self.logger.setLevel(level)
|
self.logger.setLevel(level)
|
||||||
self.logger.addHandler(self._get_error_handler(log_format))
|
self.logger.addHandler(self._get_error_handler(log_format))
|
||||||
self.logger.addHandler(self._get_warn_handler(log_format))
|
self.logger.addHandler(self._get_warning_handler(log_format))
|
||||||
self.logger.addHandler(self._get_info_handler(log_format))
|
self.logger.addHandler(self._get_info_handler(log_format))
|
||||||
self.logger.addHandler(self._get_critical_handler(log_format))
|
self.logger.addHandler(self._get_critical_handler(log_format))
|
||||||
self.logger.addHandler(self._get_debug_handler(log_format))
|
self.logger.addHandler(self._get_debug_handler(log_format))
|
||||||
|
@ -102,10 +101,10 @@ class Log:
|
||||||
|
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
def _get_warn_handler(self, log_format):
|
def _get_warning_handler(self, log_format):
|
||||||
handler = logging.StreamHandler(sys.stdout)
|
handler = logging.StreamHandler(sys.stdout)
|
||||||
handler.setLevel(logging.WARN)
|
handler.setLevel(logging.WARNING)
|
||||||
handler.addFilter(LogFilter(logging.WARN))
|
handler.addFilter(LogFilter(logging.WARNING))
|
||||||
|
|
||||||
if log_format == "json":
|
if log_format == "json":
|
||||||
handler.setFormatter(MultilineJsonFormatter(JSON_FORMAT))
|
handler.setFormatter(MultilineJsonFormatter(JSON_FORMAT))
|
||||||
|
@ -114,7 +113,7 @@ class Log:
|
||||||
else:
|
else:
|
||||||
handler.setFormatter(
|
handler.setFormatter(
|
||||||
MultilineFormatter(
|
MultilineFormatter(
|
||||||
self.warn(
|
self.warning(
|
||||||
CONSOLE_FORMAT.format(
|
CONSOLE_FORMAT.format(
|
||||||
colorama.Fore.YELLOW, colorama.Style.BRIGHT, colorama.Style.RESET_ALL
|
colorama.Fore.YELLOW, colorama.Style.BRIGHT, colorama.Style.RESET_ALL
|
||||||
)
|
)
|
||||||
|
@ -196,7 +195,7 @@ class Log:
|
||||||
|
|
||||||
self.logger.setLevel(level)
|
self.logger.setLevel(level)
|
||||||
self.logger.addHandler(self._get_error_handler(log_level))
|
self.logger.addHandler(self._get_error_handler(log_level))
|
||||||
self.logger.addHandler(self._get_warn_handler(log_level))
|
self.logger.addHandler(self._get_warning_handler(log_level))
|
||||||
self.logger.addHandler(self._get_info_handler(log_level))
|
self.logger.addHandler(self._get_info_handler(log_level))
|
||||||
self.logger.addHandler(self._get_critical_handler(log_level))
|
self.logger.addHandler(self._get_critical_handler(log_level))
|
||||||
self.logger.addHandler(self._get_debug_handler(log_level))
|
self.logger.addHandler(self._get_debug_handler(log_level))
|
||||||
|
@ -213,8 +212,8 @@ class Log:
|
||||||
"""Format error messages and return string."""
|
"""Format error messages and return string."""
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def warn(self, msg):
|
def warning(self, msg):
|
||||||
"""Format warn messages and return string."""
|
"""Format warning messages and return string."""
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def info(self, msg):
|
def info(self, msg):
|
||||||
|
@ -230,7 +229,7 @@ class Log:
|
||||||
:returns: string
|
:returns: string
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return "{}{}{}".format(color, msg, colorama.Style.RESET_ALL)
|
return f"{color}{msg}{colorama.Style.RESET_ALL}"
|
||||||
|
|
||||||
def sysexit(self, code=1):
|
def sysexit(self, code=1):
|
||||||
sys.exit(code)
|
sys.exit(code)
|
||||||
|
|
|
@ -6,21 +6,23 @@ class Host:
|
||||||
"""Represents a virtual machine or container in PVE."""
|
"""Represents a virtual machine or container in PVE."""
|
||||||
|
|
||||||
def __init__(self, vmid, hostname, ipv4_address, ipv6_address, pve_type):
|
def __init__(self, vmid, hostname, ipv4_address, ipv6_address, pve_type):
|
||||||
self.hostname = hostname
|
self.hostname = str(hostname)
|
||||||
self.ipv4_address = ipv4_address
|
self.ipv4_address = str(ipv4_address)
|
||||||
self.ipv6_address = ipv6_address
|
self.ipv6_address = str(ipv6_address)
|
||||||
self.vmid = vmid
|
self.vmid = str(vmid)
|
||||||
self.pve_type = pve_type
|
self.pve_type = str(pve_type)
|
||||||
self.labels = {}
|
self.labels = {}
|
||||||
self.labels["__meta_pve_ipv4"] = ipv4_address
|
self.add_label("ipv4", ipv4_address)
|
||||||
self.labels["__meta_pve_ipv6"] = ipv6_address
|
self.add_label("ipv6", ipv6_address)
|
||||||
self.labels["__meta_pve_name"] = hostname
|
self.add_label("name", hostname)
|
||||||
self.labels["__meta_pve_type"] = pve_type
|
self.add_label("type", pve_type)
|
||||||
self.labels["__meta_pve_vmid"] = str(vmid)
|
self.add_label("vmid", vmid)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.hostname}({self.vmid}): {self.pve_type} \
|
return (
|
||||||
{self.ipv4_address} {self.ipv6_address}"
|
f"{self.hostname}({self.vmid}): "
|
||||||
|
f"{self.pve_type} {self.ipv4_address} {self.ipv6_address}"
|
||||||
|
)
|
||||||
|
|
||||||
def add_label(self, key, value):
|
def add_label(self, key, value):
|
||||||
key = key.replace("-", "_").replace(" ", "_")
|
key = key.replace("-", "_").replace(" ", "_")
|
||||||
|
@ -36,6 +38,20 @@ class HostList:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.hosts = []
|
self.hosts = []
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
if not isinstance(other, HostList):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if len(other.hosts) != len(self.hosts):
|
||||||
|
return False
|
||||||
|
|
||||||
|
for host in self.hosts:
|
||||||
|
if other.host_exists(host):
|
||||||
|
continue
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.hosts = []
|
self.hosts = []
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
"""Init pytest unit tests."""
|
30
prometheuspvesd/test/data/config.yml
Normal file
30
prometheuspvesd/test/data/config.yml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
---
|
||||||
|
logging:
|
||||||
|
level: warning
|
||||||
|
format: console
|
||||||
|
|
||||||
|
metrics:
|
||||||
|
enabled: true
|
||||||
|
address: "127.0.0.1"
|
||||||
|
port: 8000
|
||||||
|
|
||||||
|
output_file: dummy
|
||||||
|
output_file_mode: "0640"
|
||||||
|
loop_delay: 300
|
||||||
|
service: true
|
||||||
|
|
||||||
|
exclude_state: []
|
||||||
|
exclude_vmid: []
|
||||||
|
exclude_tags: []
|
||||||
|
|
||||||
|
include_vmid: []
|
||||||
|
include_tags: []
|
||||||
|
|
||||||
|
pve:
|
||||||
|
server: proxmox.example.com
|
||||||
|
user: root
|
||||||
|
password: secure
|
||||||
|
token_name: pve_sd
|
||||||
|
token_value: 01234567-89ab-cdef-0123-456789abcdef
|
||||||
|
auth_timeout: 5
|
||||||
|
verify_ssl: true
|
1
prometheuspvesd/test/fixtures/__init__.py
vendored
1
prometheuspvesd/test/fixtures/__init__.py
vendored
|
@ -0,0 +1 @@
|
||||||
|
"""Init pytest fixtures."""
|
304
prometheuspvesd/test/fixtures/fixtures.py
vendored
304
prometheuspvesd/test/fixtures/fixtures.py
vendored
|
@ -1,18 +1,176 @@
|
||||||
"""Global pytest fixtures."""
|
"""Global pytest fixtures."""
|
||||||
|
|
||||||
|
import environs
|
||||||
import pytest
|
import pytest
|
||||||
from proxmoxer import ProxmoxAPI
|
|
||||||
|
|
||||||
from prometheuspvesd import discovery
|
from prometheuspvesd.model import Host, HostList
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def discovery_fixture(mocker):
|
def builtins():
|
||||||
mocker.patch.object(
|
return {
|
||||||
discovery.Discovery, "_auth", return_value=mocker.create_autospec(ProxmoxAPI)
|
"metrics.enabled": {
|
||||||
)
|
"default": True,
|
||||||
|
"env": "METRICS_ENABLED",
|
||||||
|
"type": environs.Env().bool,
|
||||||
|
},
|
||||||
|
"metrics.address": {
|
||||||
|
"default": "127.0.0.1",
|
||||||
|
"env": "METRICS_ADDRESS",
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"metrics.port": {"default": 8000, "env": "METRICS_PORT", "type": environs.Env().int},
|
||||||
|
"config_file": {"default": "", "env": "CONFIG_FILE", "type": environs.Env().str},
|
||||||
|
"logging.level": {
|
||||||
|
"default": "WARNING",
|
||||||
|
"env": "LOG_LEVEL",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"logging.format": {
|
||||||
|
"default": "console",
|
||||||
|
"env": "LOG_FORMAT",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"output_file": {
|
||||||
|
"default": "dummy",
|
||||||
|
"env": "OUTPUT_FILE",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"output_file_mode": {
|
||||||
|
"default": "0640",
|
||||||
|
"env": "OUTPUT_FILE_MODE",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"loop_delay": {
|
||||||
|
"default": 300,
|
||||||
|
"env": "LOOP_DELAY",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().int,
|
||||||
|
},
|
||||||
|
"service": {"default": False, "env": "SERVICE", "file": True, "type": environs.Env().bool},
|
||||||
|
"exclude_state": {
|
||||||
|
"default": [],
|
||||||
|
"env": "EXCLUDE_STATE",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().list,
|
||||||
|
},
|
||||||
|
"exclude_vmid": {
|
||||||
|
"default": [],
|
||||||
|
"env": "EXCLUDE_VMID",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().list,
|
||||||
|
},
|
||||||
|
"exclude_tags": {
|
||||||
|
"default": [],
|
||||||
|
"env": "EXCLUDE_TAGS",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().list,
|
||||||
|
},
|
||||||
|
"include_vmid": {
|
||||||
|
"default": [],
|
||||||
|
"env": "INCLUDE_VMID",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().list,
|
||||||
|
},
|
||||||
|
"include_tags": {
|
||||||
|
"default": [],
|
||||||
|
"env": "INCLUDE_TAGS",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().list,
|
||||||
|
},
|
||||||
|
"pve.server": {
|
||||||
|
"default": "dummyserver",
|
||||||
|
"env": "PVE_SERVER",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"pve.user": {
|
||||||
|
"default": "dummyuser",
|
||||||
|
"env": "PVE_USER",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"pve.password": {
|
||||||
|
"default": "dummypass",
|
||||||
|
"env": "PVE_PASSWORD",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"pve.token_name": {
|
||||||
|
"default": "dummyname",
|
||||||
|
"env": "PVE_TOKEN_NAME",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"pve.token_value": {
|
||||||
|
"default": "dummyvalue",
|
||||||
|
"env": "PVE_TOKEN_VALUE",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().str,
|
||||||
|
},
|
||||||
|
"pve.auth_timeout": {
|
||||||
|
"default": 5,
|
||||||
|
"env": "PVE_AUTH_TIMEOUT",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().int,
|
||||||
|
},
|
||||||
|
"pve.verify_ssl": {
|
||||||
|
"default": True,
|
||||||
|
"env": "PVE_VERIFY_SSL",
|
||||||
|
"file": True,
|
||||||
|
"type": environs.Env().bool,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
return discovery.Discovery()
|
|
||||||
|
@pytest.fixture
|
||||||
|
def defaults():
|
||||||
|
return {
|
||||||
|
"exclude_state": [],
|
||||||
|
"exclude_tags": [],
|
||||||
|
"exclude_vmid": [],
|
||||||
|
"include_tags": [],
|
||||||
|
"include_vmid": [],
|
||||||
|
"logging": {"format": "console", "level": "WARNING"},
|
||||||
|
"loop_delay": 300,
|
||||||
|
"metrics": {"address": "127.0.0.1", "enabled": True, "port": 8000},
|
||||||
|
"output_file": "dummy",
|
||||||
|
"output_file_mode": "0640",
|
||||||
|
"pve": {
|
||||||
|
"auth_timeout": 5,
|
||||||
|
"password": "",
|
||||||
|
"server": "",
|
||||||
|
"user": "",
|
||||||
|
"token_name": "",
|
||||||
|
"token_value": "",
|
||||||
|
"verify_ssl": True,
|
||||||
|
},
|
||||||
|
"service": True,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def nodes():
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"level": "",
|
||||||
|
"id": "node/example-node",
|
||||||
|
"disk": 4783488,
|
||||||
|
"cpu": 0.0935113631167406,
|
||||||
|
"maxcpu": 24,
|
||||||
|
"maxmem": 142073272990,
|
||||||
|
"mem": 135884478304,
|
||||||
|
"node": "example-node",
|
||||||
|
"type": "node",
|
||||||
|
"status": "online",
|
||||||
|
"maxdisk": 504209920,
|
||||||
|
"uptime": 200,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -34,7 +192,8 @@ def qemus():
|
||||||
"disk": 0,
|
"disk": 0,
|
||||||
"status": "running",
|
"status": "running",
|
||||||
"netout": 12159205236,
|
"netout": 12159205236,
|
||||||
"mem": 496179157
|
"mem": 496179157,
|
||||||
|
"tags": "unmonitored;excluded;postgres",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"diskwrite": 0,
|
"diskwrite": 0,
|
||||||
|
@ -52,17 +211,57 @@ def qemus():
|
||||||
"disk": 0,
|
"disk": 0,
|
||||||
"status": "running",
|
"status": "running",
|
||||||
"netout": 12159205236,
|
"netout": 12159205236,
|
||||||
"mem": 496179157
|
"mem": 496179157,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"diskwrite": 0,
|
||||||
|
"vmid": "102",
|
||||||
|
"name": "102.example.com",
|
||||||
|
"cpu": 0.0202130478509556,
|
||||||
|
"diskread": 0,
|
||||||
|
"template": "",
|
||||||
|
"uptime": 3101505,
|
||||||
|
"maxdisk": 26843545600,
|
||||||
|
"maxmem": 1073741824,
|
||||||
|
"pid": "1765",
|
||||||
|
"cpus": 1,
|
||||||
|
"netin": 2856071643,
|
||||||
|
"disk": 0,
|
||||||
|
"status": "prelaunch",
|
||||||
|
"netout": 12159205236,
|
||||||
|
"mem": 496179157,
|
||||||
|
"tags": "monitored",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def instance_config():
|
||||||
|
return {
|
||||||
|
"name": "102.example.com",
|
||||||
|
"description": '{"groups": "test-group"}',
|
||||||
|
"net0": "virtio=D8-85-75-47-2E-8D,bridge=vmbr122,ip=192.0.2.25,ip=2001:db8::666:77:8888",
|
||||||
|
"cpu": 2,
|
||||||
|
"cores": 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def agent_info():
|
||||||
|
return {
|
||||||
|
"supported_commands": [
|
||||||
|
{"name": "guest-network-get-interfaces", "enabled": True, "success-response": True}
|
||||||
|
],
|
||||||
|
"version": "5.2.0",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def addresses():
|
def addresses():
|
||||||
return {
|
return {
|
||||||
"ipv4_valid": [
|
"ipv4_valid": [
|
||||||
"192.168.0.1",
|
"192.0.2.1",
|
||||||
"10.0.0.1",
|
"198.51.100.1",
|
||||||
],
|
],
|
||||||
"ipv4_invalid": [
|
"ipv4_invalid": [
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
|
@ -90,16 +289,8 @@ def networks():
|
||||||
{
|
{
|
||||||
"hardware-address": "00:00:00:00:00:00",
|
"hardware-address": "00:00:00:00:00:00",
|
||||||
"ip-addresses": [
|
"ip-addresses": [
|
||||||
{
|
{"ip-address": "127.0.0.1", "ip-address-type": "ipv4", "prefix": 8},
|
||||||
"ip-address": "127.0.0.1",
|
{"ip-address": "::1", "ip-address-type": "ipv6", "prefix": 128},
|
||||||
"ip-address-type": "ipv4",
|
|
||||||
"prefix": 8
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ip-address": "::1",
|
|
||||||
"ip-address-type": "ipv6",
|
|
||||||
"prefix": 128
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
"name": "lo",
|
"name": "lo",
|
||||||
"statistics": {
|
"statistics": {
|
||||||
|
@ -110,26 +301,18 @@ def networks():
|
||||||
"tx-bytes": 9280,
|
"tx-bytes": 9280,
|
||||||
"tx-dropped": 0,
|
"tx-dropped": 0,
|
||||||
"tx-errs": 0,
|
"tx-errs": 0,
|
||||||
"tx-packets": 92
|
"tx-packets": 92,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"hardware-address": "92:0b:bd:c1:f8:39",
|
"hardware-address": "92:0b:bd:c1:f8:39",
|
||||||
"ip-addresses": [
|
"ip-addresses": [
|
||||||
|
{"ip-address": "192.0.2.1", "ip-address-type": "ipv4", "prefix": 32},
|
||||||
|
{"ip-address": "192.0.2.4", "ip-address-type": "ipv4", "prefix": 32},
|
||||||
{
|
{
|
||||||
"ip-address": "10.168.0.1",
|
"ip-address": "2001:db8:3333:4444:5555:6666:7777:8888",
|
||||||
"ip-address-type": "ipv4",
|
|
||||||
"prefix": 32
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ip-address": "10.168.0.2",
|
|
||||||
"ip-address-type": "ipv4",
|
|
||||||
"prefix": 32
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ip-address": "2001:cdba:3333:4444:5555:6666:7777:8888",
|
|
||||||
"ip-address-type": "ipv6",
|
"ip-address-type": "ipv6",
|
||||||
"prefix": 64
|
"prefix": 64,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"name": "eth0",
|
"name": "eth0",
|
||||||
|
@ -141,7 +324,54 @@ def networks():
|
||||||
"tx-bytes": 12185866619,
|
"tx-bytes": 12185866619,
|
||||||
"tx-dropped": 0,
|
"tx-dropped": 0,
|
||||||
"tx-errs": 0,
|
"tx-errs": 0,
|
||||||
"tx-packets": 14423878
|
"tx-packets": 14423878,
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
{"hardware-address": "ba:97:85:bd:9a:a5", "name": "eth1"},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def inventory():
|
||||||
|
hostlist = HostList()
|
||||||
|
hostlist.add_host(Host("100", "100.example.com", "192.0.2.1", False, "qemu"))
|
||||||
|
hostlist.add_host(Host("101", "101.example.com", "192.0.2.2", False, "qemu"))
|
||||||
|
hostlist.add_host(Host("102", "102.example.com", "192.0.2.3", False, "qemu"))
|
||||||
|
|
||||||
|
return hostlist
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def labels():
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"targets": ["100.example.com"],
|
||||||
|
"labels": {
|
||||||
|
"__meta_pve_ipv4": "192.0.2.1",
|
||||||
|
"__meta_pve_ipv6": "False",
|
||||||
|
"__meta_pve_name": "100.example.com",
|
||||||
|
"__meta_pve_type": "qemu",
|
||||||
|
"__meta_pve_vmid": "100",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"targets": ["101.example.com"],
|
||||||
|
"labels": {
|
||||||
|
"__meta_pve_ipv4": "192.0.2.2",
|
||||||
|
"__meta_pve_ipv6": "False",
|
||||||
|
"__meta_pve_name": "101.example.com",
|
||||||
|
"__meta_pve_type": "qemu",
|
||||||
|
"__meta_pve_vmid": "101",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"targets": ["102.example.com"],
|
||||||
|
"labels": {
|
||||||
|
"__meta_pve_ipv4": "192.0.2.3",
|
||||||
|
"__meta_pve_ipv6": "False",
|
||||||
|
"__meta_pve_name": "102.example.com",
|
||||||
|
"__meta_pve_type": "qemu",
|
||||||
|
"__meta_pve_vmid": "102",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
60
prometheuspvesd/test/unit/conftest.py
Normal file
60
prometheuspvesd/test/unit/conftest.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
"""Pytest conftest fixtures."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from _pytest.logging import LogCaptureHandler
|
||||||
|
|
||||||
|
from prometheuspvesd.utils import Singleton
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def reset_singletons():
|
||||||
|
Singleton._instances = {}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def reset_os_environment():
|
||||||
|
os.environ.clear()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def reset_sys_argv():
|
||||||
|
sys.argv = ["prometheus-pve-sd"]
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def local_caplog_fn(level=logging.INFO, name="prometheuspvesd"):
|
||||||
|
"""
|
||||||
|
Context manager that captures records from non-propagating loggers.
|
||||||
|
|
||||||
|
After the end of the 'with' statement, the log level is restored to its original
|
||||||
|
value. Code adapted from https://github.com/pytest-dev/pytest/issues/3697#issuecomment-790925527.
|
||||||
|
|
||||||
|
:param int level: The level.
|
||||||
|
:param logging.Logger logger: The logger to update.
|
||||||
|
"""
|
||||||
|
|
||||||
|
logger = logging.getLogger(name)
|
||||||
|
|
||||||
|
old_level = logger.level
|
||||||
|
logger.setLevel(level)
|
||||||
|
|
||||||
|
handler = LogCaptureHandler()
|
||||||
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
try:
|
||||||
|
yield handler
|
||||||
|
finally:
|
||||||
|
logger.setLevel(old_level)
|
||||||
|
logger.removeHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def local_caplog():
|
||||||
|
"""Fixture that yields a context manager for capturing records from non-propagating loggers."""
|
||||||
|
|
||||||
|
yield local_caplog_fn
|
146
prometheuspvesd/test/unit/test_cli.py
Normal file
146
prometheuspvesd/test/unit/test_cli.py
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
"""Test CLI class."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from proxmoxer import ProxmoxAPI
|
||||||
|
|
||||||
|
import prometheuspvesd.exception
|
||||||
|
from prometheuspvesd.cli import PrometheusSD
|
||||||
|
from prometheuspvesd.client import ProxmoxClient
|
||||||
|
from prometheuspvesd.config import Config
|
||||||
|
from prometheuspvesd.discovery import Discovery
|
||||||
|
from prometheuspvesd.exception import APIError
|
||||||
|
from prometheuspvesd.logger import Log
|
||||||
|
|
||||||
|
pytest_plugins = [
|
||||||
|
"prometheuspvesd.test.fixtures.fixtures",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_cli_required_error(mocker, capsys):
|
||||||
|
mocker.patch.object(ProxmoxClient, "_auth", return_value=mocker.create_autospec(ProxmoxAPI))
|
||||||
|
mocker.patch.object(PrometheusSD, "_fetch", return_value=True)
|
||||||
|
|
||||||
|
with pytest.raises(SystemExit) as e:
|
||||||
|
PrometheusSD()
|
||||||
|
|
||||||
|
stdout, stderr = capsys.readouterr()
|
||||||
|
assert "Option 'pve.server' is required but not set" in stderr
|
||||||
|
assert e.value.code == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"testinput",
|
||||||
|
[
|
||||||
|
{"pve.user": "dummy", "pve.password": "", "pve.token_name": "", "pve.token_value": ""},
|
||||||
|
{
|
||||||
|
"pve.user": "dummy",
|
||||||
|
"pve.password": "",
|
||||||
|
"pve.token_name": "dummy",
|
||||||
|
"pve.token_value": "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pve.user": "dummy",
|
||||||
|
"pve.password": "",
|
||||||
|
"pve.token_name": "",
|
||||||
|
"pve.token_value": "dummy",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_cli_auth_required_error(mocker, capsys, builtins, testinput):
|
||||||
|
for key, value in testinput.items():
|
||||||
|
builtins[key]["default"] = value
|
||||||
|
|
||||||
|
mocker.patch.dict(Config.SETTINGS, builtins)
|
||||||
|
mocker.patch.object(ProxmoxClient, "_auth", return_value=mocker.create_autospec(ProxmoxAPI))
|
||||||
|
mocker.patch.object(PrometheusSD, "_fetch", return_value=True)
|
||||||
|
|
||||||
|
with pytest.raises(SystemExit) as e:
|
||||||
|
PrometheusSD()
|
||||||
|
|
||||||
|
stdout, stderr = capsys.readouterr()
|
||||||
|
assert (
|
||||||
|
"Either 'pve.password' or 'pve.token_name' and 'pve.token_value' are required but not set"
|
||||||
|
in stderr
|
||||||
|
)
|
||||||
|
assert e.value.code == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"testinput",
|
||||||
|
[
|
||||||
|
{"pve.password": "dummy", "pve.token_name": "", "pve.token_value": ""},
|
||||||
|
{"pve.password": "", "pve.token_name": "dummy", "pve.token_value": "dummy"},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_cli_auth_no_error(mocker, builtins, testinput):
|
||||||
|
for key, value in testinput.items():
|
||||||
|
builtins[key]["default"] = value
|
||||||
|
|
||||||
|
mocker.patch.dict(Config.SETTINGS, builtins)
|
||||||
|
mocker.patch.object(ProxmoxClient, "_auth", return_value=mocker.create_autospec(ProxmoxAPI))
|
||||||
|
mocker.patch.object(PrometheusSD, "_fetch", return_value=True)
|
||||||
|
|
||||||
|
psd = PrometheusSD()
|
||||||
|
|
||||||
|
for key, value in testinput.items():
|
||||||
|
assert psd.config.config["pve"][key.split(".")[1]] == value
|
||||||
|
|
||||||
|
|
||||||
|
def test_cli_config_error(mocker, capsys):
|
||||||
|
mocker.patch(
|
||||||
|
"prometheuspvesd.config.SingleConfig.__init__",
|
||||||
|
side_effect=prometheuspvesd.exception.ConfigError("Dummy Config Exception"),
|
||||||
|
)
|
||||||
|
mocker.patch.object(ProxmoxClient, "_auth", return_value=mocker.create_autospec(ProxmoxAPI))
|
||||||
|
mocker.patch.object(PrometheusSD, "_fetch", return_value=True)
|
||||||
|
|
||||||
|
with pytest.raises(SystemExit) as e:
|
||||||
|
PrometheusSD()
|
||||||
|
|
||||||
|
stdout, stderr = capsys.readouterr()
|
||||||
|
assert "Dummy Config Exception" in stderr
|
||||||
|
assert e.value.code == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_cli_log_error(mocker, capsys):
|
||||||
|
mocker.patch.object(Log, "update_logger", side_effect=ValueError("Dummy Loglevel Exception"))
|
||||||
|
mocker.patch.object(ProxmoxClient, "_auth", return_value=mocker.create_autospec(ProxmoxAPI))
|
||||||
|
mocker.patch.object(PrometheusSD, "_fetch", return_value=True)
|
||||||
|
|
||||||
|
with pytest.raises(SystemExit) as e:
|
||||||
|
PrometheusSD()
|
||||||
|
|
||||||
|
stdout, stderr = capsys.readouterr()
|
||||||
|
assert "Dummy Loglevel Exception" in stderr
|
||||||
|
assert e.value.code == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_cli_api_error(mocker, builtins, capsys):
|
||||||
|
mocker.patch.dict(Config.SETTINGS, builtins)
|
||||||
|
mocker.patch.object(ProxmoxClient, "_auth", side_effect=APIError("Dummy API Exception"))
|
||||||
|
mocker.patch.object(PrometheusSD, "_fetch", return_value=True)
|
||||||
|
|
||||||
|
with pytest.raises(SystemExit) as e:
|
||||||
|
PrometheusSD()
|
||||||
|
|
||||||
|
stdout, stderr = capsys.readouterr()
|
||||||
|
assert "Proxmoxer API error: Dummy API Exception" in stderr
|
||||||
|
assert e.value.code == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_cli_write(mocker, tmp_path, builtins, inventory, labels):
|
||||||
|
temp = tmp_path / "temp.txt"
|
||||||
|
out = tmp_path / "out.txt"
|
||||||
|
|
||||||
|
builtins["output_file"]["default"] = out.as_posix()
|
||||||
|
|
||||||
|
mocker.patch.dict(Config.SETTINGS, builtins)
|
||||||
|
mocker.patch.object(ProxmoxClient, "_auth", return_value=mocker.create_autospec(ProxmoxAPI))
|
||||||
|
mocker.patch.object(Discovery, "propagate", return_value=inventory)
|
||||||
|
mocker.patch("tempfile.NamedTemporaryFile", return_value=temp.open("w"))
|
||||||
|
|
||||||
|
psd = PrometheusSD()
|
||||||
|
assert json.loads(out.read_text()) == labels
|
||||||
|
assert oct(out.stat().st_mode & 0o777) == oct(int(psd.config.config["output_file_mode"], 8))
|
38
prometheuspvesd/test/unit/test_config.py
Normal file
38
prometheuspvesd/test/unit/test_config.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
"""Test Config class."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import ruamel.yaml
|
||||||
|
|
||||||
|
import prometheuspvesd.exception
|
||||||
|
from prometheuspvesd.config import Config
|
||||||
|
|
||||||
|
pytest_plugins = [
|
||||||
|
"prometheuspvesd.test.fixtures.fixtures",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_yaml_config(mocker, defaults):
|
||||||
|
mocker.patch(
|
||||||
|
"prometheuspvesd.config.default_config_file", "./prometheuspvesd/test/data/config.yml"
|
||||||
|
)
|
||||||
|
config = Config()
|
||||||
|
|
||||||
|
defaults["pve"]["user"] = "root"
|
||||||
|
defaults["pve"]["password"] = "secure"
|
||||||
|
defaults["pve"]["server"] = "proxmox.example.com"
|
||||||
|
defaults["pve"]["token_name"] = "pve_sd"
|
||||||
|
defaults["pve"]["token_value"] = "01234567-89ab-cdef-0123-456789abcdef"
|
||||||
|
|
||||||
|
assert config.config == defaults
|
||||||
|
|
||||||
|
|
||||||
|
def test_yaml_config_error(mocker):
|
||||||
|
mocker.patch(
|
||||||
|
"prometheuspvesd.config.default_config_file", "./prometheuspvesd/test/data/config.yml"
|
||||||
|
)
|
||||||
|
mocker.patch.object(ruamel.yaml.YAML, "load", side_effect=ruamel.yaml.composer.ComposerError)
|
||||||
|
|
||||||
|
with pytest.raises(prometheuspvesd.exception.ConfigError) as e:
|
||||||
|
Config()
|
||||||
|
|
||||||
|
assert "Unable to read config file ./prometheuspvesd/test/data/config.yml" in str(e.value)
|
|
@ -1,49 +1,134 @@
|
||||||
"""Test Autostop class."""
|
"""Test Discovery class."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from proxmoxer import ProxmoxAPI
|
||||||
|
|
||||||
|
from prometheuspvesd.client import ProxmoxClient
|
||||||
|
from prometheuspvesd.discovery import Discovery
|
||||||
|
|
||||||
pytest_plugins = [
|
pytest_plugins = [
|
||||||
"prometheuspvesd.test.fixtures.fixtures",
|
"prometheuspvesd.test.fixtures.fixtures",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_mock(*args):
|
def records_to_messages(records):
|
||||||
networks = args[0]
|
return [r.getMessage() for r in records]
|
||||||
args = args[1:]
|
|
||||||
|
|
||||||
if "info" in args:
|
|
||||||
return True
|
|
||||||
if "network-get-interfaces" in args:
|
|
||||||
return {"result": networks}
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def test_exclude(discovery_fixture, qemus):
|
@pytest.fixture
|
||||||
discovery_fixture.config.config["exclude_vmid"] = ["100", "101"]
|
def discovery(mocker):
|
||||||
|
mocker.patch.object(ProxmoxClient, "_auth", return_value=mocker.create_autospec(ProxmoxAPI))
|
||||||
|
|
||||||
expected = []
|
return Discovery()
|
||||||
filtered = discovery_fixture._exclude(qemus)
|
|
||||||
|
|
||||||
assert filtered == expected
|
|
||||||
|
|
||||||
|
|
||||||
def test_validate_ip(discovery_fixture, addresses):
|
def test_exclude_vmid(discovery, qemus):
|
||||||
|
discovery.config.config["exclude_vmid"] = ["100", "101", "102"]
|
||||||
|
filtered = discovery._filter(qemus)
|
||||||
|
|
||||||
|
assert len(filtered) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_exclude_state(discovery, qemus):
|
||||||
|
discovery.config.config["exclude_state"] = ["prelaunch"]
|
||||||
|
filtered = discovery._filter(qemus)
|
||||||
|
|
||||||
|
assert len(filtered) == 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_exclude_tags(discovery, qemus, local_caplog):
|
||||||
|
discovery.config.config["exclude_tags"] = ["unmonitored"]
|
||||||
|
|
||||||
|
with local_caplog(level=logging.DEBUG) as caplog:
|
||||||
|
filtered = discovery._filter(qemus)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"vmid 100: discovered tags: ['unmonitored', 'excluded', 'postgres']"
|
||||||
|
in records_to_messages(caplog.records)
|
||||||
|
)
|
||||||
|
assert "vmid 100: excluded by tags: ['unmonitored']"
|
||||||
|
assert len(filtered) == 2
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"testinput,expected",
|
||||||
|
[
|
||||||
|
(["monitored"], 1),
|
||||||
|
(["monitored", "postgres"], 2),
|
||||||
|
([], 3),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_include_tags(discovery, qemus, testinput, expected):
|
||||||
|
discovery.config.config["include_tags"] = testinput
|
||||||
|
filtered = discovery._filter(qemus)
|
||||||
|
|
||||||
|
assert len(filtered) == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"testinput,expected",
|
||||||
|
[
|
||||||
|
(["101", "100"], 2),
|
||||||
|
([], 3),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_include_vmid(discovery, qemus, testinput, expected):
|
||||||
|
discovery.config.config["include_vmid"] = testinput
|
||||||
|
filtered = discovery._filter(qemus)
|
||||||
|
|
||||||
|
assert len(filtered) == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_include_and_exclude_tags(discovery, qemus):
|
||||||
|
discovery.config.config["include_tags"] = ["postgres"]
|
||||||
|
discovery.config.config["exclude_tags"] = ["unmonitored"]
|
||||||
|
filtered = discovery._filter(qemus)
|
||||||
|
|
||||||
|
assert len(filtered) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_ip(discovery, addresses):
|
||||||
# IPv4 validation
|
# IPv4 validation
|
||||||
for address in addresses["ipv4_valid"]:
|
for address in addresses["ipv4_valid"]:
|
||||||
assert discovery_fixture._validate_ip(address)
|
assert discovery._validate_ip(address)
|
||||||
for address in addresses["ipv4_invalid"]:
|
for address in addresses["ipv4_invalid"]:
|
||||||
assert not discovery_fixture._validate_ip(address)
|
assert not discovery._validate_ip(address)
|
||||||
|
|
||||||
# IPv6 validation
|
# IPv6 validation
|
||||||
for address in addresses["ipv6_valid"]:
|
for address in addresses["ipv6_valid"]:
|
||||||
assert discovery_fixture._validate_ip(address)
|
assert discovery._validate_ip(address)
|
||||||
for address in addresses["ipv6_invalid"]:
|
for address in addresses["ipv6_invalid"]:
|
||||||
assert not discovery_fixture._validate_ip(address)
|
assert not discovery._validate_ip(address)
|
||||||
|
|
||||||
|
|
||||||
def test_get_ip_addresses(mocker, discovery_fixture, networks):
|
def test_get_ip_addresses(mocker, discovery, networks):
|
||||||
discovery_fixture.client.get.side_effect = lambda *args: get_mock(networks, *args)
|
mocker.patch.object(ProxmoxClient, "get_network_interfaces", return_value=networks)
|
||||||
|
|
||||||
assert discovery_fixture._get_ip_addresses("qemu", "dummy", "dummy") == (
|
assert discovery._get_ip_addresses("qemu", "dummy", "dummy") == (
|
||||||
networks[1]["ip-addresses"][0]["ip-address"],
|
networks[1]["ip-addresses"][0]["ip-address"],
|
||||||
networks[1]["ip-addresses"][2]["ip-address"],
|
networks[1]["ip-addresses"][2]["ip-address"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_ip_addresses_from_instance_config(mocker, discovery, instance_config):
|
||||||
|
mocker.patch.object(ProxmoxClient, "get_network_interfaces", return_value=[])
|
||||||
|
mocker.patch.object(ProxmoxClient, "get_instance_config", return_value=instance_config)
|
||||||
|
|
||||||
|
assert discovery._get_ip_addresses("qemu", "dummy", "dummy") == (
|
||||||
|
"192.0.2.25",
|
||||||
|
"2001:db8::666:77:8888",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_propagate(
|
||||||
|
mocker, discovery, nodes, qemus, instance_config, agent_info, networks, inventory
|
||||||
|
):
|
||||||
|
mocker.patch.object(ProxmoxClient, "get_nodes", return_value=nodes)
|
||||||
|
mocker.patch.object(ProxmoxClient, "get_all_vms", return_value=qemus)
|
||||||
|
mocker.patch.object(ProxmoxClient, "get_instance_config", return_value=instance_config)
|
||||||
|
mocker.patch.object(ProxmoxClient, "get_agent_info", return_value=agent_info)
|
||||||
|
mocker.patch.object(ProxmoxClient, "get_network_interfaces", return_value=networks)
|
||||||
|
|
||||||
|
assert discovery.propagate() == inventory
|
||||||
|
|
58
prometheuspvesd/test/unit/test_model.py
Normal file
58
prometheuspvesd/test/unit/test_model.py
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
"""Test Host class."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from prometheuspvesd.model import Host
|
||||||
|
|
||||||
|
pytest_plugins = [
|
||||||
|
"prometheuspvesd.test.fixtures.fixtures",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"testinput,expected",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
{
|
||||||
|
"vmid": 101,
|
||||||
|
"hostname": "host1",
|
||||||
|
"ipv4_address": False,
|
||||||
|
"ipv6_address": False,
|
||||||
|
"pve_type": "qemu",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__meta_pve_vmid": "101",
|
||||||
|
"__meta_pve_name": "host1",
|
||||||
|
"__meta_pve_ipv4": "False",
|
||||||
|
"__meta_pve_ipv6": "False",
|
||||||
|
"__meta_pve_type": "qemu",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{
|
||||||
|
"vmid": "202",
|
||||||
|
"hostname": "host2",
|
||||||
|
"ipv4_address": "129.168.0.1",
|
||||||
|
"ipv6_address": "2001:db8:3333:4444:5555:6666:7777:8888",
|
||||||
|
"pve_type": "qemu",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__meta_pve_vmid": "202",
|
||||||
|
"__meta_pve_name": "host2",
|
||||||
|
"__meta_pve_ipv4": "129.168.0.1",
|
||||||
|
"__meta_pve_ipv6": "2001:db8:3333:4444:5555:6666:7777:8888",
|
||||||
|
"__meta_pve_type": "qemu",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_host(testinput, expected):
|
||||||
|
host = Host(
|
||||||
|
testinput["vmid"],
|
||||||
|
testinput["hostname"],
|
||||||
|
testinput["ipv4_address"],
|
||||||
|
testinput["ipv6_address"],
|
||||||
|
testinput["pve_type"],
|
||||||
|
)
|
||||||
|
|
||||||
|
assert host.labels == expected
|
|
@ -1,7 +1,29 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""Global utility methods and classes."""
|
"""Global utility methods and classes."""
|
||||||
|
|
||||||
from distutils.util import strtobool
|
|
||||||
|
def strtobool(value):
|
||||||
|
"""Convert a string representation of truth to true or false."""
|
||||||
|
|
||||||
|
_map = {
|
||||||
|
"y": True,
|
||||||
|
"yes": True,
|
||||||
|
"t": True,
|
||||||
|
"true": True,
|
||||||
|
"on": True,
|
||||||
|
"1": True,
|
||||||
|
"n": False,
|
||||||
|
"no": False,
|
||||||
|
"f": False,
|
||||||
|
"false": False,
|
||||||
|
"off": False,
|
||||||
|
"0": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
return _map[str(value).lower()]
|
||||||
|
except KeyError as err:
|
||||||
|
raise ValueError(f'"{value}" is not a valid bool value') from err
|
||||||
|
|
||||||
|
|
||||||
def to_bool(string):
|
def to_bool(string):
|
||||||
|
@ -15,5 +37,5 @@ class Singleton(type):
|
||||||
|
|
||||||
def __call__(cls, *args, **kwargs):
|
def __call__(cls, *args, **kwargs):
|
||||||
if cls not in cls._instances:
|
if cls not in cls._instances:
|
||||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
cls._instances[cls] = super().__call__(*args, **kwargs)
|
||||||
return cls._instances[cls]
|
return cls._instances[cls]
|
||||||
|
|
137
pyproject.toml
137
pyproject.toml
|
@ -10,10 +10,11 @@ classifiers = [
|
||||||
"Natural Language :: English",
|
"Natural Language :: English",
|
||||||
"Operating System :: POSIX",
|
"Operating System :: POSIX",
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"Programming Language :: Python :: 3.7",
|
|
||||||
"Programming Language :: Python :: 3.8",
|
"Programming Language :: Python :: 3.8",
|
||||||
"Programming Language :: Python :: 3.9",
|
"Programming Language :: Python :: 3.9",
|
||||||
"Programming Language :: Python :: 3.10",
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
"Topic :: Utilities",
|
"Topic :: Utilities",
|
||||||
]
|
]
|
||||||
description = "Prometheus Service Discovery for Proxmox VE."
|
description = "Prometheus Service Discovery for Proxmox VE."
|
||||||
|
@ -29,66 +30,108 @@ repository = "https://github.com/thegeeklab/prometheus-pve-sd/"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
anyconfig = "0.12.0"
|
anyconfig = "0.14.0"
|
||||||
appdirs = "1.4.4"
|
appdirs = "1.4.4"
|
||||||
colorama = "0.4.4"
|
colorama = "0.4.6"
|
||||||
environs = "9.5.0"
|
environs = "11.0.0"
|
||||||
jsonschema = "4.4.0"
|
jsonschema = "4.22.0"
|
||||||
nested-lookup = "0.2.23"
|
nested-lookup = "0.2.25"
|
||||||
prometheus-client = "0.13.1"
|
prometheus-client = "0.20.0"
|
||||||
proxmoxer = "1.2.0"
|
proxmoxer = "2.0.1"
|
||||||
python = "^3.7.0"
|
python = "^3.8.0"
|
||||||
python-json-logger = "2.0.2"
|
python-json-logger = "2.0.7"
|
||||||
requests = "2.27.1"
|
requests = "2.31.0"
|
||||||
"ruamel.yaml" = "0.17.21"
|
"ruamel.yaml" = "0.18.6"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
|
||||||
bandit = "1.7.2"
|
|
||||||
flake8 = "4.0.1"
|
|
||||||
flake8-blind-except = "0.2.0"
|
|
||||||
flake8-builtins = "1.5.3"
|
|
||||||
flake8-docstrings = "1.6.0"
|
|
||||||
flake8-eradicate = "1.2.0"
|
|
||||||
flake8-isort = "4.1.1"
|
|
||||||
flake8-logging-format = "0.6.0"
|
|
||||||
flake8-pep3101 = "1.3.0"
|
|
||||||
flake8-polyfill = "1.0.2"
|
|
||||||
flake8-quotes = "3.3.1"
|
|
||||||
pep8-naming = "0.12.1"
|
|
||||||
pydocstyle = "6.1.1"
|
|
||||||
pytest = "7.0.1"
|
|
||||||
pytest-cov = "3.0.0"
|
|
||||||
pytest-mock = "3.7.0"
|
|
||||||
yapf = "0.32.0"
|
|
||||||
toml = "0.10.2"
|
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
prometheus-pve-sd = "prometheuspvesd.cli:main"
|
prometheus-pve-sd = "prometheuspvesd.cli:main"
|
||||||
|
|
||||||
|
[tool.poetry.group.dev.dependencies]
|
||||||
|
ruff = "0.4.5"
|
||||||
|
pytest = "8.2.1"
|
||||||
|
pytest-mock = "3.14.0"
|
||||||
|
pytest-cov = "5.0.0"
|
||||||
|
toml = "0.10.2"
|
||||||
|
|
||||||
[tool.poetry-dynamic-versioning]
|
[tool.poetry-dynamic-versioning]
|
||||||
enable = true
|
enable = true
|
||||||
style = "semver"
|
style = "semver"
|
||||||
vcs = "git"
|
vcs = "git"
|
||||||
|
|
||||||
[tool.isort]
|
|
||||||
default_section = "THIRDPARTY"
|
|
||||||
force_single_line = true
|
|
||||||
line_length = 99
|
|
||||||
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
|
|
||||||
skip_glob = ["**/.env*", "**/env/*", "**/.venv/*", "**/docs/*"]
|
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
addopts = "prometheuspvesd --cov=prometheuspvesd --cov-report=xml:coverage.xml --cov-report=term --cov-append --no-cov-on-fail"
|
addopts = "prometheuspvesd --cov=prometheuspvesd --cov-report=xml:coverage.xml --cov-report=term-missing --no-cov-on-fail --cov-fail-under=80"
|
||||||
filterwarnings = [
|
filterwarnings = ["ignore::FutureWarning", "ignore::DeprecationWarning"]
|
||||||
"ignore::FutureWarning",
|
|
||||||
"ignore:.*distutils.*:DeprecationWarning",
|
|
||||||
"ignore:.*collections.*:DeprecationWarning",
|
|
||||||
"ignore:.*pep8.*:FutureWarning",
|
|
||||||
]
|
|
||||||
|
|
||||||
[tool.coverage.run]
|
[tool.coverage.run]
|
||||||
omit = ["**/test/*"]
|
omit = ["**/test/*"]
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry_dynamic_versioning.backend"
|
||||||
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"]
|
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"]
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
exclude = [
|
||||||
|
".git",
|
||||||
|
"__pycache__",
|
||||||
|
"build",
|
||||||
|
"dist",
|
||||||
|
"*.pyc",
|
||||||
|
"*.egg-info",
|
||||||
|
".cache",
|
||||||
|
".eggs",
|
||||||
|
"env*",
|
||||||
|
]
|
||||||
|
|
||||||
|
line-length = 99
|
||||||
|
indent-width = 4
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
# Explanation of errors
|
||||||
|
#
|
||||||
|
# D102: Missing docstring in public method
|
||||||
|
# D103: Missing docstring in public function
|
||||||
|
# D105: Missing docstring in magic method
|
||||||
|
# D107: Missing docstring in __init__
|
||||||
|
# D202: No blank lines allowed after function docstring
|
||||||
|
# D203: One blank line required before class docstring
|
||||||
|
# D212: Multi-line docstring summary should start at the first line
|
||||||
|
ignore = [
|
||||||
|
"D102",
|
||||||
|
"D103",
|
||||||
|
"D105",
|
||||||
|
"D107",
|
||||||
|
"D202",
|
||||||
|
"D203",
|
||||||
|
"D212",
|
||||||
|
"UP038",
|
||||||
|
"RUF012",
|
||||||
|
]
|
||||||
|
select = [
|
||||||
|
"D",
|
||||||
|
"E",
|
||||||
|
"F",
|
||||||
|
"Q",
|
||||||
|
"W",
|
||||||
|
"I",
|
||||||
|
"S",
|
||||||
|
"BLE",
|
||||||
|
"N",
|
||||||
|
"UP",
|
||||||
|
"B",
|
||||||
|
"A",
|
||||||
|
"C4",
|
||||||
|
"T20",
|
||||||
|
"SIM",
|
||||||
|
"RET",
|
||||||
|
"ARG",
|
||||||
|
"ERA",
|
||||||
|
"RUF",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff.lint.per-file-ignores]
|
||||||
|
"test_*.py" = ["S"]
|
||||||
|
|
||||||
|
[tool.ruff.format]
|
||||||
|
quote-style = "double"
|
||||||
|
indent-style = "space"
|
||||||
|
line-ending = "lf"
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
"extends": ["github>thegeeklab/renovate-presets"]
|
"extends": ["github>thegeeklab/renovate-presets"],
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"matchManagers": ["woodpecker"],
|
||||||
|
"matchFileNames": [".woodpecker/test.yml"],
|
||||||
|
"matchPackageNames": ["docker.io/library/python"],
|
||||||
|
"enabled": false
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
20
setup.cfg
20
setup.cfg
|
@ -1,20 +0,0 @@
|
||||||
[flake8]
|
|
||||||
# Explanation of errors
|
|
||||||
#
|
|
||||||
# D102: Missing docstring in public method
|
|
||||||
# D103: Missing docstring in public function
|
|
||||||
# D105: Missing docstring in magic method
|
|
||||||
# D107: Missing docstring in __init__
|
|
||||||
# D202: No blank lines allowed after function docstring
|
|
||||||
# W503:Line break occurred before a binary operator
|
|
||||||
ignore = D102, D103, D105, D107, D202, W503
|
|
||||||
max-line-length = 99
|
|
||||||
inline-quotes = double
|
|
||||||
exclude = .git, __pycache__, build, dist, test, *.pyc, *.egg-info, .cache, .eggs, env*
|
|
||||||
|
|
||||||
[yapf]
|
|
||||||
based_on_style = google
|
|
||||||
column_limit = 99
|
|
||||||
dedent_closing_brackets = true
|
|
||||||
coalesce_brackets = true
|
|
||||||
split_before_logical_operator = true
|
|
Loading…
Reference in New Issue
Block a user