Linuxfabrik / monitoring-plugins

220+ check plugins for Icinga and other Nagios-compatible monitoring applications. Each plugin is a standalone command line tool (written in Python) that provides a specific type of check.
https://linuxfabrik.ch
The Unlicense
214 stars 49 forks source link

dhcp-scope-usage: convert string to float #778

Closed SilverAlex85 closed 3 weeks ago

SilverAlex85 commented 3 weeks ago

This issue respects the following points:

Which variant of the Monitoring Plugins do you use?

Bug description

Output from check dhcp-scope-usage different from shell and icinga, result is shown below. I think second issue or error is the convertion from a powershell error message and in Icingaweb the convertion from a string to a float value.

Steps to reproduce - Plugin call

./dhcp-scope-usage --hostname=domaincontroller03.****.local --winrm-hostname=192.168.20.3 --winrm-username=Administrator --winrm-password=**** --winrm-domain=****.local --winrm-transport=ntlm

Steps to reproduce - Data

Output from shell:

winrm/__init__.py:83: UserWarning: There was a problem converting the Powershell error message: not well-formed (invalid token): line 1, column 205
Everything is ok.

* 192.168.20.0: 21.56863% used
* 192.168.30.0: 46.47887% used
* 192.168.40.0: 30.43478% used
* 192.168.10.0: 13.2% used
* 192.168.15.0: 1.0% used
* 192.168.20.0: 24.5% used
* 192.168.30.0: 0.0% used
* 192.168.70.0: 3.2% used
* 192.168.80.0: 0.4% used
* 192.168.90.0: 6.8% used|'scope_192.168.20.0'=21.56863%;80;90;0;100 'scope_192.168.30.0'=46.47887%;80;90;0;100 'scope_192.168.40.0'=30.43478%;80;90;0;100 'scope_192.168.10.0'=13.2%;80;90;0;100 'scope_192.168.15.0'=1.0%;80;90;0;100 'scope_192.168.20.0'=24.5%;80;90;0;100 'scope_192.168.30.0'=0.0%;80;90;0;100 'scope_192.168.70.0'=3.2%;80;90;0;100 'scope_192.168.80.0'=0.4%;80;90;0;100 'scope_192.168.90.0'=6.8%;80;90;0;100

Output from Icinga2:

winrm/__init__.py:83: UserWarning: There was a problem converting the Powershell error message: not well-formed (invalid token): line 1, column 205
Traceback (most recent call last):
  File "dhcp-scope-usage.py", line 205, in 'module'
  File "dhcp-scope-usage.py", line 182, in main
  File "locale.py", line 338, in atof
ValueError: could not convert string to float: '21,​56863'

Environment

Linux 5.15.0-119-generic #129-Ubuntu SMP Fri Aug 2 19:25:20 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
icinga2 - The Icinga 2 network monitoring daemon (version: r2.14.2-1)
Director - 1.11.1
IciningaDB - 1.1.2
Windows Server 2022 Build 20348.2655 (DHCP and DNS role)

Plugin Version

dhcp-scope-usage: v2023112901 by Linuxfabrik GmbH, Zurich/Switzerland

Python version

3.10.12

List of Python modules

CommandNotFound     _weakrefset         hashlib             rlcompleter
DistUpgrade         _xxsubinterpreters  heapq               runpy
HweSupportStatus    _xxtestfuzz         hmac                samba
NvidiaDetector      _yaml               html                sched
OpenSSL             _zoneinfo           http                secrets
Quirks              abc                 httplib2            secretstorage
UbuntuDrivers       aifc                hyperlink           select
UpdateManager       antigravity         idna                selectors
__future__          apport              imaplib             serial
_abc                apport_python_hook  imghdr              service_identity
_aix_support        apt                 imp                 setuptools
_ast                apt_inst            importlib           shelve
_asyncio            apt_pkg             importlib_metadata  shlex
_bisect             aptsources          incremental         shutil
_blake2             argparse            inspect             signal
_bootsubprocess     array               io                  site
_bz2                ast                 ipaddress           sitecustomize
_cffi_backend       asynchat            itertools           six
_codecs             asyncio             janitor             smtpd
_codecs_cn          asyncore            jeepney             smtplib
_codecs_hk          atexit              jinja2              snack
_codecs_iso2022     attr                json                sndhdr
_codecs_jp          audioop             jsonpatch           socket
_codecs_kr          automat             jsonpointer         socketserver
_codecs_tw          babel               jsonschema          softwareproperties
_collections        base64              jwt                 sos
_collections_abc    bcrypt              keyring             spnego
_compat_pickle      bdb                 keyword             spwd
_compression        binascii            landscape           sqlite3
_contextvars        binhex              launchpadlib        sre_compile
_crypt              bisect              ldb                 sre_constants
_csv                blinker             lib2to3             sre_parse
_ctypes             builtins            linecache           ssh_import_id
_ctypes_test        bz2                 locale              ssl
_curses             cProfile            logging             stat
_curses_panel       calendar            lsb_release         statistics
_datetime           certifi             lzma                string
_dbm                cgi                 magic               stringprep
_dbus_bindings      cgitb               mailbox             struct
_dbus_glib_bindings chardet             mailcap             subprocess
_decimal            chunk               mailstore           sunau
_distutils_hack     click               markupsafe          symtable
_distutils_system_mod cloudinit           marshal             sys
_elementtree        cmath               math                sysconfig
_functools          cmd                 mimetypes           syslog
_gdbm               code                mmap                systemd
_hashlib            codecs              modulefinder        tabnanny
_heapq              codeop              more_itertools      talloc
_imp                collections         multiprocessing     tarfile
_io                 colorama            netifaces           tdb
_json               colorsys            netrc               telnetlib
_ldb_text           compileall          nis                 tempfile
_locale             concurrent          nntplib             termios
_lsprof             configobj           ntpath              test
_lzma               configparser        nturl2path          textwrap
_markupbase         constantly          numbers             this
_md5                contextlib          oauthlib            threading
_multibytecodec     contextvars         opcode              time
_multiprocessing    copy                operator            timeit
_opcode             copyreg             optparse            token
_operator           crypt               os                  tokenize
_osx_support        cryptography        ossaudiodev         trace
_pickle             csv                 pathlib             traceback
_posixshmem         ctypes              pdb                 tracemalloc
_posixsubprocess    curses              pexpect             tty
_py_abc             dataclasses         pickle              turtle
_pydecimal          datetime            pickletools         twisted
_pyio               dbm                 pip                 types
_pyrsistent_version dbus                pipes               typing
_queue              deb822              pkg_resources       uaclient
_random             debconf             pkgutil             ufw
_sha1               debian              platform            unicodedata
_sha256             debian_bundle       plistlib            unittest
_sha3               decimal             poplib              urllib
_sha512             difflib             posix               urllib3
_signal             dis                 posixpath           uu
_sitebuiltins       distro              pprint              uuid
_snack              distro_info         problem_report      validate
_socket             distutils           profile             venv
_sqlite3            doctest             pstats              wadllib
_sre                email               pty                 warnings
_ssl                encodings           ptyprocess          wave
_stat               enum                pvectorc            weakref
_statistics         errno               pwd                 webbrowser
_string             faulthandler        py_compile          wheel
_strptime           fcntl               pyasn1              winrm
_struct             filecmp             pyasn1_modules      wsgiref
_symtable           fileinput           pyclbr              xdrlib
_sysconfigdata__linux_x86_64-linux-gnu fnmatch             pydoc               xkit
_sysconfigdata__x86_64-linux-gnu fractions           pydoc_data          xml
_tdb_text           ftplib              pyexpat             xmlrpc
_testbuffer         functools           pygtkcompat         xmltodict
_testcapi           gc                  pyparsing           xxlimited
_testclinic         genericpath         pyrsistent          xxlimited_35
_testimportmultiple getopt              pytz                xxsubtype
_testinternalcapi   getpass             queue               yaml
_testmultiphase     gettext             quopri              zipapp
_thread             gi                  random              zipfile
_threading_local    glob                re                  zipimport
_tracemalloc        gpg                 readline            zipp
_uuid               graphlib            reprlib             zlib
_version            grp                 requests            zoneinfo
_warnings           gzip                requests_ntlm       zope
_weakref            hamcrest            resource

Additional Information

No response

markuslf commented 3 weeks ago

What's the powershell output of Get-DhcpServerv4ScopeStatistics -ComputerName "domaincontroller03.yourdomain.local"?

SilverAlex85 commented 3 weeks ago

Lokks fine, below the output:

PS C:\Windows\system32> Get-DhcpServerv4ScopeStatistics -ComputerName "domaincontroller03.*****.local"

ScopeId          Free            InUse           PercentageInUse  Reserved        Pending         SuperscopeName
-------          ----            -----           ---------------  --------        -------         --------------
192.168.20.0       40              11              21,56863         6               0               Servernetz
192.168.30.0       38              33              46,47887         12              0               Managementnetz
192.168.40.0       176             77              30,43478         2               0               VoIP
192.168.10.0       217             33              13,2             6               0               Hospiz
192.168.15.0       198             2               1                2               0               Buchhaltung
192.168.20.0       151             49              24,5             10              0               Verwaltungsnetz
192.168.30.0       200             0               0                0               0               WLAN
192.168.70.0       242             8               3,2              2               0
192.168.80.0       249             1               0,4              1               0
192.168.90.0       233             17              6,8              5               0
markuslf commented 3 weeks ago

Is it german locale?

markuslf commented 3 weeks ago

I removed the handling of the fraction part PercentageInUse in https://github.com/Linuxfabrik/monitoring-plugins/commit/413dd07184cb4b27e622ed328efacddf6bb3430e - this could have been the source of the error according to the output in Icinga.

markuslf commented 3 weeks ago

Could you please try the new version?

SilverAlex85 commented 3 weeks ago

Sorry, both Linux and Windows Server 2022 are german localization. Give some minutes, i give it a try and report back to you.

SilverAlex85 commented 3 weeks ago

I have tried the new version and looks good, below the output:

/usr/local/lib/python3.10/dist-packages/winrm/init.py:87: UserWarning: There was a problem converting the Powershell error message: not well-formed (invalid token): line 1, column 205 warnings.warn("There was a problem converting the Powershell error " "message: %s" % (e)) Everything is ok.

The only confusing thing is this winrm/powershell message.

Thanks for the change.

markuslf commented 3 weeks ago

This is a powershell or winrm library related issue. Can you do me a favor, run this on your Linux directly in Python and report back the output?


import winrm

session = winrm.Session('192.168.20.3', auth=('Administrator@mydomain.local', 'mypassword'), transport='ntlm')
session.run_ps('Get-DhcpServerv4ScopeStatistics -ComputerName "domaincontroller03.****.local"')
SilverAlex85 commented 3 weeks ago

Same error message:

nagios@monitor01:/usr/lib64/nagios/plugins$ ./dhcp-scope-usage --hostname=domaincontroller03.bssnetz.local --winrm-hostname=192.168.20.3 --winrm-username=administrator --winrm-password= --winrm-domain=.local --winrm-transport=ntlm /usr/local/lib/python3.10/dist-packages/winrm/init.py:87: UserWarning: There was a problem converting the Powershell error message: not well-formed (invalid token): line 1, column 205 warnings.warn("There was a problem converting the Powershell error " "message: %s" % (e)) Everything is ok.

markuslf commented 3 weeks ago

I think you misunderstood me :-)

Please start python on your monitor01, paste in this script, adjust it and tell me the result.


import winrm

session = winrm.Session('192.168.20.3', auth=('Administrator@mydomain.local', 'mypassword'), transport='ntlm')
session.run_ps('Get-DhcpServerv4ScopeStatistics -ComputerName "domaincontroller03.mydomain.local"')
SilverAlex85 commented 3 weeks ago

Sorry, I had almost guessed that. Below the output:

Python 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import winrm
>>> session = winrm.Session('192.168.20.3', auth=('administrator@domain.local', '*****'), transport='ntlm')
>>> session.run_ps('Get-DhcpServerv4ScopeStatistics -ComputerName "domaincontroller03.bssnetz.local"')
/usr/local/lib/python3.10/dist-packages/winrm/__init__.py:87: UserWarning: There was a problem converting the Powershell error message: not well-formed (invalid token): line 1, column 205
  warnings.warn("There was a problem converting the Powershell error " "message: %s" % (e))
<Response code 0, out "b'\r\nScopeId          F'", err "b'#< CLIXML\r\n<Objs Ver'">
>>>

I hope this helps.

markuslf commented 3 weeks ago

Not much, but your Powershell returns an error that starts with #< CLIXML\r\n<Objs Ver. The winrm library stumbles over it because it's invalid XML. There is nothing we can do about this, and you need to investigate further. I will close this issue.

However, you may get the full Powershell error by using this code snippet:


import winrm
session = winrm.Session('192.168.20.3', auth=('administrator@domain.local', '*****'), transport='ntlm')
result = session.run_ps('Get-DhcpServerv4ScopeStatistics -ComputerName "domaincontroller03.bssnetz.local"')
print(result.std_err)
SilverAlex85 commented 3 weeks ago

okay thanks for your help.