Problema:

Es necesario hacer consultas a servidores Windows desde Linux usando Windows Management Instrumentation (WMI).

Solución:

Para poder realizar consultas en necesario contar con un cliente wmi. Seguir el procedimento para instalarlo en Centos 7.

1. Descargar en wmi en www.atomicorp.com

wget http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/wmi-1.3.14-4.el7.art.x86_64.rpm

--2019-02-06 18:36:16-- http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/wmi-1.3.14-4.el7.art.x86_64.rpm
Connecting to 10.64.114.5:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 8075232 (7.7M) [application/x-rpm]
Saving to: ‘wmi-1.3.14-4.el7.art.x86_64.rpm’

100%[======================================================================================================================================================================>] 8,075,232 6.72MB/s in 1.1s

2019-02-06 18:36:17 (6.72 MB/s) - ‘wmi-1.3.14-4.el7.art.x86_64.rpm’ saved [8075232/8075232]

 

2. Instalar wmi

yum install wmi-1.3.14-4.el7.art.x86_64.rpm

Loaded plugins: fastestmirror
Examining wmi-1.3.14-4.el7.art.x86_64.rpm: wmi-1.3.14-4.el7.art.x86_64
Marking wmi-1.3.14-4.el7.art.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package wmi.x86_64 0:1.3.14-4.el7.art will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================================================================================================
Installing:
wmi x86_64 1.3.14-4.el7.art /wmi-1.3.14-4.el7.art.x86_64 36 M

Transaction Summary
================================================================================================================================================================================================================
Install 1 Package

Total size: 36 M
Installed size: 36 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : wmi-1.3.14-4.el7.art.x86_64 1/1
Verifying : wmi-1.3.14-4.el7.art.x86_64 1/1

Installed:
wmi.x86_64 0:1.3.14-4.el7.art

Complete!

 

3. Probar

 

[root@aurlenserver ~]# wmic ?
Usage: [-?|--help] [--usage] [-d|--debuglevel DEBUGLEVEL] [--debug-stderr]
        [-s|--configfile CONFIGFILE] [--option=name=value]
        [-l|--log-basename LOGFILEBASE] [--leak-report] [--leak-report-full]
        [-R|--name-resolve NAME-RESOLVE-ORDER]
        [-O|--socket-options SOCKETOPTIONS] [-n|--netbiosname NETBIOSNAME]
        [-W|--workgroup WORKGROUP] [--realm=REALM] [-i|--scope SCOPE]
        [-m|--maxprotocol MAXPROTOCOL] [-U|--user [DOMAIN\]USERNAME[%PASSWORD]]
        [-N|--no-pass] [--password=STRING] [-A|--authentication-file FILE]
        [-S|--signing on|off|required] [-P|--machine-pass]
        [--simple-bind-dn=STRING] [-k|--kerberos STRING]
        [--use-security-mechanisms=STRING] [-V|--version] [--namespace=STRING]
        [--delimiter=STRING]
        //host query

Example: wmic -U [domain/]adminuser%password //host "select * from Win32_ComputerSystem"

 

Ejemplo:

Obtener de manera remota la memoria del servidor Windows.

IP del servidor Windows: 192.168.123.58
Usuario de Windows: zabbixmonitor
Contraseña de Windows: SuperPassword

 

wmic -U zabbixmonitor%SuperPassword //192.168.123.58 "select TotalPhysicalMemory from Win32_ComputerSystem"

CLASS: Win32_ComputerSystem
Name|TotalPhysicalMemory
Windows2008R2srv|17179336704