Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Monitor: remote queries via ssh #1398

Open
wants to merge 142 commits into
base: develop
Choose a base branch
from

Conversation

wsw70
Copy link
Contributor

@wsw70 wsw70 commented May 7, 2024

This is a preliminary PR for a new Monitor that uses SSH to connect to a remote machine, run a command, parse it results to extract a value which is then monitored.

Why preliminary?

  • it is fully working but since the paradigm is different than other monitors I am looking for comments and ideas for changes. A RFC of sorts.
  • it uses match which is a Python 3.10+ feature. I will make it retro-compatible with 3.7 as a new branch when this PR is tested/reviewed, awaiting for Simplemonitor to be, someday, bumped to 3.27 (EBV - Expected Bump Version)
  • I have it working for some time already with various systems and, well, it works. But YMMV. And I want to know typical mileages to account for them in the code.

Important note for @jamesoff : I had to change in envconfig.py ConfigParser to RawConfigParser otherwise the regex I read in was escaped (see the commit). I do not think it changes anything because as far as I could tell you do not rely on escaping when reading the configuration.

So try it out (git checkout monitor_remote_ssh) and let me know!

simplemonitor/Monitors/remote_ssh.py Fixed Show resolved Hide resolved
simplemonitor/util/envconfig.py Fixed Show resolved Hide resolved
@jamesoff
Copy link
Owner

jamesoff commented May 7, 2024

Thanks! I'm away until next week so won't be able to take a proper look at this until then - I'm not ignoring it :)

Copy link
Owner

@jamesoff jamesoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a quick look (I'm travelling again!) and this looks pretty good. Added a couple of thoughts :)

I'm fine with the change to ConfigParser, don't think that will cause any issues.

simplemonitor/Monitors/remote_ssh.py Outdated Show resolved Hide resolved
simplemonitor/Monitors/remote_ssh.py Outdated Show resolved Hide resolved
simplemonitor/Monitors/remote_ssh.py Outdated Show resolved Hide resolved
# extract and cast the actual value
command_result = stdout.read().decode("utf-8") # let's hope for the best
client.close() # it's only now that we are done with the client
actual_value = re.match(self.regex, command_result).groups()[0]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if it would be better to require a named group in the regexp, so that can be picked out specifically rather than requiring the user to craft a regexp which makes the first capturing group the one they need?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that but what would be the value of several capturing groups? There is just one that will be used anyway.

if test_succeeded:
return self.record_success(self.success_message.format(actual_value))
else:
return self.record_fail(f"actual value: {actual_value} | operator: {self.operator} | target value: {self.target_value}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any value in letting the user also customise the failure message in a similar fashion to the success one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require some adjustments - I will have to test how doable it is to pass the format to the actual logging message (right now there is just one "placeholder" ({}) for actual_value in the configuration string)

@jamesoff
Copy link
Owner

I just bumped the version of parakimo on the develop branch btw (finally merged dependabot's PR)

@wsw70
Copy link
Contributor Author

wsw70 commented May 21, 2024

I'm fine with the change to ConfigParser, don't think that will cause any issues.

done in f5bb0ef

wsw70 and others added 7 commits November 5, 2024 14:30
Bumps [freezegun](https://github.com/spulec/freezegun) from 1.4.0 to 1.5.0.
- [Release notes](https://github.com/spulec/freezegun/releases)
- [Changelog](https://github.com/spulec/freezegun/blob/master/CHANGELOG)
- [Commits](spulec/freezegun@1.4.0...1.5.0)

---
updated-dependencies:
- dependency-name: freezegun
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [ping3](https://github.com/kyan001/ping3) from 4.0.5 to 4.0.8.
- [Release notes](https://github.com/kyan001/ping3/releases)
- [Changelog](https://github.com/kyan001/ping3/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kyan001/ping3/commits)

---
updated-dependencies:
- dependency-name: ping3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [pyaarlo](https://github.com/twrecked/pyaarlo) from 0.8.0.4 to 0.8.0.6.
- [Release notes](https://github.com/twrecked/pyaarlo/releases)
- [Changelog](https://github.com/twrecked/pyaarlo/blob/master/changelog)
- [Commits](https://github.com/twrecked/pyaarlo/commits)

---
updated-dependencies:
- dependency-name: pyaarlo
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.3 to 3.1.4.
- [Release notes](https://github.com/pallets/jinja/releases)
- [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst)
- [Commits](pallets/jinja@3.1.3...3.1.4)

---
updated-dependencies:
- dependency-name: jinja2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [pyaarlo](https://github.com/twrecked/pyaarlo) from 0.8.0.6 to 0.8.0.7.
- [Release notes](https://github.com/twrecked/pyaarlo/releases)
- [Changelog](https://github.com/twrecked/pyaarlo/blob/master/changelog)
- [Commits](https://github.com/twrecked/pyaarlo/commits)

---
updated-dependencies:
- dependency-name: pyaarlo
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
dependabot bot and others added 29 commits November 5, 2024 14:30
Bumps [bandit](https://github.com/PyCQA/bandit) from 1.7.5 to 1.7.10.
- [Release notes](https://github.com/PyCQA/bandit/releases)
- [Commits](PyCQA/bandit@1.7.5...1.7.10)

---
updated-dependencies:
- dependency-name: bandit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [requests](https://github.com/psf/requests) from 2.31.0 to 2.32.3.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](psf/requests@v2.31.0...v2.32.3)

---
updated-dependencies:
- dependency-name: requests
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [types-pyopenssl](https://github.com/python/typeshed) from 23.3.0.0 to 24.1.0.20240722.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-pyopenssl
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [psutil](https://github.com/giampaolo/psutil) from 6.0.0 to 6.1.0.
- [Changelog](https://github.com/giampaolo/psutil/blob/master/HISTORY.rst)
- [Commits](giampaolo/psutil@release-6.0.0...release-6.1.0)

---
updated-dependencies:
- dependency-name: psutil
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [types-paramiko](https://github.com/python/typeshed) from 3.4.0.20240103 to 3.5.0.20240928.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-paramiko
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [types-setuptools](https://github.com/python/typeshed) from 75.2.0.20241018 to 75.2.0.20241019.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-setuptools
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [mypy](https://github.com/python/mypy) from 1.11.2 to 1.12.1.
- [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md)
- [Commits](python/mypy@v1.11.2...v1.12.1)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [pywin32](https://github.com/mhammond/pywin32) from 307 to 308.
- [Release notes](https://github.com/mhammond/pywin32/releases)
- [Changelog](https://github.com/mhammond/pywin32/blob/main/CHANGES.txt)
- [Commits](https://github.com/mhammond/pywin32/commits)

---
updated-dependencies:
- dependency-name: pywin32
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [types-python-dateutil](https://github.com/python/typeshed) from 2.8.19.14 to 2.9.0.20241003.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-python-dateutil
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [setuptools](https://github.com/pypa/setuptools) from 68.0.0 to 75.2.0.
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v68.0.0...v75.2.0)

---
updated-dependencies:
- dependency-name: setuptools
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [mypy](https://github.com/python/mypy) from 1.12.1 to 1.13.0.
- [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md)
- [Commits](python/mypy@v1.12.1...v1.13.0)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [ruff](https://github.com/astral-sh/ruff) from 0.6.9 to 0.7.0.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](astral-sh/ruff@0.6.9...0.7.0)

---
updated-dependencies:
- dependency-name: ruff
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [ruff](https://github.com/astral-sh/ruff) from 0.7.0 to 0.7.1.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](astral-sh/ruff@0.7.0...0.7.1)

---
updated-dependencies:
- dependency-name: ruff
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [types-setuptools](https://github.com/python/typeshed) from 75.2.0.20241019 to 75.2.0.20241025.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-setuptools
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 4.1.0 to 5.0.0.
- [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst)
- [Commits](pytest-dev/pytest-cov@v4.1.0...v5.0.0)

---
updated-dependencies:
- dependency-name: pytest-cov
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [importlib-metadata](https://github.com/python/importlib_metadata) from 4.2.0 to 8.5.0.
- [Release notes](https://github.com/python/importlib_metadata/releases)
- [Changelog](https://github.com/python/importlib_metadata/blob/main/NEWS.rst)
- [Commits](python/importlib_metadata@v4.2.0...v8.5.0)

---
updated-dependencies:
- dependency-name: importlib-metadata
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [ruff](https://github.com/astral-sh/ruff) from 0.7.1 to 0.7.2.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](astral-sh/ruff@0.7.1...0.7.2)

---
updated-dependencies:
- dependency-name: ruff
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [colorlog](https://github.com/borntyping/python-colorlog) from 6.8.2 to 6.9.0.
- [Release notes](https://github.com/borntyping/python-colorlog/releases)
- [Commits](borntyping/python-colorlog@v6.8.2...v6.9.0)

---
updated-dependencies:
- dependency-name: colorlog
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [types-setuptools](https://github.com/python/typeshed) from 75.2.0.20241025 to 75.3.0.20241105.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-setuptools
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [setuptools](https://github.com/pypa/setuptools) from 75.2.0 to 75.3.0.
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v75.2.0...v75.3.0)

---
updated-dependencies:
- dependency-name: setuptools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
By design the user is providing the command here.
@jamesoff
Copy link
Owner

jamesoff commented Nov 5, 2024

@wsw70 with apologies for sitting on this for so long (it's been a difficult summer!) I've updated it to pass the tests and stuff. It's pulled the minimum Python version up a bit (match) but that should be ok nowadays.

I adjusted some of the logic around the comparison slightly to both appease the type checker and enforce the logic from the comments about only allowing greater/less than on ints. I also changed the host key handling from auto-accept to reject which matches the use in the unifi monitor, and added a note to the docs about it.

Otherwise this looks good, maybe you want to test it out from this version in the PR to make sure my changes didn't break anything?

Before merging I want to double-check the update to Python 3.10 doesn't affect anything else but that aside I think this is ready :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants