Technitium DNS server zone high-availability

Nagios check_wmi_plus on ubuntu

check_wmi_plus is an agentless nagios script that allow to collect or monitor windows devices or services via wmic. 

check_wmi_plus is an extended version of check_wmi. It uses the Windows Management Interface to check for common services (cpu, disk, sevices, eventlog, and more ) on Windows machines. It requires the open source wmi client for Linux.

1. Download latest open source wmi client, as of now is 1.4.1 from https://edcint.co.nz/checkwmiplus/releases/other-software/

2. Install build dependencies on Ubuntu server (as of now I am using Ubuntu 22.04 LTS).

sudo apt-get install build-essential python-is-python3

3. Untar the wmi source package and build from the source.

tar zxvf wmi-1.4.1.tar.gz
cd /wmi-1.4.1
sudo make "CPP=gcc -E -ffreestanding"

4. If encounter below errors, remove the 3 respective line at Samba/source/lib/tls.tls.c.

TLSCHECK(gnutls_set_default_priority(tls->session));
/*gnutls_certificate_type_set_priority(tls->session, cert_type_priority);*/
TLSCHECK(gnutls_credentials_set(tls->session, GNUTLS_CRD_CERTIFICATE, tls->xcred));

talloc_set_destructor(tls, tls_destructor);

gnutls_transport_set_ptr(tls->session, (gnutls_transport_ptr)tls);
gnutls_transport_set_pull_function(tls->session, (gnutls_pull_func)tls_pull);
gnutls_transport_set_push_function(tls->session, (gnutls_push_func)tls_push);
/*gnutls_transport_set_lowat(tls->session, 0);*/

/usr/bin/ld: bin/static/libtls.a(tls.o): in function `tls_init_server':
/home/administrator/wmi-1.4.1/Samba/source/lib/tls/tls.c:508: undefined reference to `gnutls_transport_set_lowat'
/usr/bin/ld: bin/static/libtls.a(tls.o): in function `tls_init_client':
/home/administrator/wmi-1.4.1/Samba/source/lib/tls/tls.c:579: undefined reference to `gnutls_certificate_type_set_priority'
/usr/bin/ld: /home/administrator/wmi-1.4.1/Samba/source/lib/tls/tls.c:587: undefined reference to `gnutls_transport_set_lowat'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:11883: bin/wmic] Error 1
make[1]: Leaving directory '/home/administrator/wmi-1.4.1/Samba/source'

5. Once done, double check the wmic binary is created at Samba/source/bin.

Use of uninitialized value in pattern match (m//) at ./script/cflags.pl line 15, <IN> line 1212.
Linking bin/static/libcli_lsa.a
Compiling winbind/wb_async_helpers.c
Use of uninitialized value in pattern match (m//) at ./script/cflags.pl line 15, <IN> line 1212.
Linking bin/static/libwb_helper.a
Compiling torture/util.c
Use of uninitialized value in pattern match (m//) at ./script/cflags.pl line 15, <IN> line 1212.
Compiling torture/util_smb.c
Use of uninitialized value in pattern match (m//) at ./script/cflags.pl line 15, <IN> line 1212.
Linking bin/static/libtorture_util.a
Linking bin/shared/libtorture.so.0.0.1
Linking bin/shared/librpc_ndr_protected_storage.so.0.0.1
Linking bin/shared/libwinbind-client.so.0.0.1
Linking bin/shared/libndr_dsbackup.so.0.0.1
Linking bin/shared/libndr_winstation.so.0.0.1
Linking bin/shared/libndr_wkssvc.so.0.0.1
Linking bin/shared/libshare.so.0.0.1
make[1]: Leaving directory '/home/administrator/wmi-1.4.1/Samba/source'
cd Samba/source ; \
cp bin/winexe /bin ; \
cp bin/wmic /bin ; \
cp bin/shared/*async_wmi_lib.so.0* /lib/python
rm -rf /lib/python/pysamba
cp -r pysamba /lib/python

administrator@ubuntu:~/wmi-1.4.1/Samba/source/bin$ ls
asn1_compile  compile_et  modules  pkgconfig  shared  static  torture  winexe  wmic
administrator@ubuntu:~/wmi-1.4.1/Samba/source/bin$

6. Let test the wmic remote query with windows credential.

administrator@ubuntu:~/wmi-1.4.1/Samba/source/bin$ ./wmic -U domain/administrator%password //PC1 "SELECT Model, Manufacturer, WakeUpType, PartOfDomain FROM Win32_ComputerSystem"
CLASS: Win32_ComputerSystem
Manufacturer|Model|Name|PartOfDomain|WakeUpType
VMware, Inc.|VMware Virtual Platform|PC1|True|6

7. Copy the wmic binary to /usr/local/bin.

sudo cp  ~/wmi-1.4.1/Samba/source/bin/wmic /usr/local/bin

8. Install dependencies for check_wmi_plus.pl. Make sure nagios4 is installed and working.

sudo apt-get install nagios4 libnumber-format-perl libconfig-inifiles-perl libdatetime-perl

9. Download the latest check_wmi_plus script from https://edcint.co.nz/checkwmiplus/releases.

10. Untar the check_wmi_plus package, copy the perl script and configuration files to their appropriate location.

tar zxvf check_wmi_plus.v1.66.tar.gz
chmod +x check_wmi_plus.pl
sudo cp check_wmi_plus.pl /usr/lib/nagios/plugins/
sudo cp -r etc/check_wmi_plus /etc

11. Configure /etc/check_wmi_plus/check_wmi_plus.conf with below settings.

sudo cp /etc/check_wmi_plus/check_wmi_plus.conf.sample  /etc/check_wmi_plus/check_wmi_plus.conf

# Set the full path where the plugin is installed
# You might not even use this variable if you have different locations for everything
$base_dir='/etc/check_wmi_plus'; # CHANGE THIS IF NEEDED

# This is the full path location of the wmic command
# - standard value "/usr/bin/wmic" since this is where it goes when it is compiled
$wmic_command="/usr/local/bin/wmic"; # CHANGE THIS IF NEEDED

12. Test the check_wmi_plus.pl with windows credential.

administrator@nagios:/usr/lib/nagios/plugins$ ./check_wmi_plus.pl -H 192.168.41.180 -u USER -p PASSWORD -m checkcpu
OK (Sample Period 3 sec) - Average CPU Utilisation 0.47%|'Avg CPU Utilisation'=0.47%;

https://edcint.co.nz/checkwmiplus/faq/can-you-show-me-some-example-command-lines/

https://github.com/speartail/checkwmiplus/blob/master/check_wmi_plus.README.txt

https://exchange.nagios.org/directory/Plugins/Operating-Systems/Windows/WMI/Check-WMI-Plus/details

Comments