Es wird gezeigt wie über das Tool WMIC von Samba4 die Windows Management Instrumentation (WMI) Schnittstelle von Windows ohne separaten Client abgefragt werden kann.
Dabei wird die WMI Query Language (WQL) verwendet und verschiedene Werte abgefragt.
Geplant sind Abfragen für:
Prozessor Last
Speicher Auslastung (+Pagefile)
System (Uptime, OS-Version, ...)
Freier Festplattenspeicherplatz
Zustand eines MS-Clusters
eventuell spezifische Exchange, AD, MSSQL-Counter
eventuell Eventlogs
2. Seite 206.10.2010| Thomas Sesselmann ITCF
Ziel:Clientless Windows-Monitoring
• Problem laufende Infrastruktur/Server
Zusätzlicher Client/Software ist ein Eingriff
Schlechte Erfahrung mit anderen Agenten
neue Probleme letzte Änderung Schuld
• Vorteile:
• Keine zusätzliche Software notwendig
• Muss nicht jedes System „anfassen“
• Standardmethoden nutzen
WMI
3. Seite 306.10.2010| Thomas Sesselmann ITCF
Windows Management Instrumentation
• Erweiterung von CIM (Common Information Model)
• Implementierungvon WBEM (Web Based Enterprise Mangement)
• Kernfunktion von Windows (nicht ohne lauffähig)
• Zugriff zu Einstellungen und aktuellen Werten
• Inventardaten von Hardware + Software + BIOS
• Computer neu starten
• Ereignisprotokolle
• PerformanceMonitor Daten
• Registry
• Programme, Prozesse, Dienste und Warteschlangen
• Ordner und Dateien des Dateisystems
• …
4. Seite 406.10.2010| Thomas Sesselmann ITCF
WMI Query Language (WQL)
• Zugriff auf WMI
• SQL ähnlicher Syntax
• nur Select unterstützt (lesen)
SELECT Caption,BuildNumber
FROM Win32_OperatingSystem
Microsoft(R) Windows(R) Server 2003,
Standard Edition|3790
5. Seite 506.10.2010| Thomas Sesselmann ITCF
Wege zu WMI
• NSClient++ (CheckWMI)
• OpenPegasus (WBEM-WMI-Gateway)
• HP WMI Mapper Tool (WBEM-WMI-Gateway)
• WMI Explorer
• .NET
• Samba4 wmic (WMI-Client)
6. Seite 606.10.2010| Thomas Sesselmann ITCF
WMI-Mapper vs. WMI-Client
• Extra Server (Windows) mit HTTP Abfragen
• Skalierbarkeit
• Abhänigkeit von WBEM-Server
7. Seite 706.10.2010| Thomas Sesselmann ITCF
Zugriff zu WMI
• CIFS/Samba Ports
• User mit Recht WMI lesen zu können
• http://forums.cacti.net/about30438-0-asc-15.html
• User zur Performance Monitor/Logging Group hinzufügen
• keine weiteren Admin-Rechte
9. Seite 906.10.2010| Thomas Sesselmann ITCF
WMI-Client kompilieren
• Ubuntu Paket (http://packages.ubuntu.com/hardy/python/wmi-client)
• kompilieren von Samba:
git clone git://git.samba.org/samba.git samba
cd samba/source4/lib/wmi/tools
make wmic # fails
cd ../../../..
git checkout -b v4-0-test origin/v4-0-test
cd source4
./autogen.sh
./configure
make #fails => vi main.mk #WMI fails :(
10. Seite 1006.10.2010| Thomas Sesselmann ITCF
WMI-Client kompilieren
• Ubuntu Paket (http://packages.ubuntu.com/hardy/python/wmi-client)
• kompilieren von Zenoss :
ver=1.3.13
wget
http://dev.zenoss.org/svn/trunk/inst/externallibs/
wmi-$ver.tar.bz2
tar -xjf wmi-$ver.tar.bz2
cd wmi-$ver
export ZENHOME=/tmp/xx
make
find /tmp/xx/
11. Seite 1106.10.2010| Thomas Sesselmann ITCF
WMI-Client testen
• Abfrage Tests mit Domain User
• Neuere wmic-Version mit ‚--delimiter‘-Option
$ wmic --help # usage
$ wmic -U AD/nagios%xxx //win01
"select * from Win32_ComputerSystem"
…
$ wmic –U AD/nagios%xxx //win01
"select dnshostname,domain
from Win32_ComputerSystem"
CLASS: Win32_ComputerSystem
DNSHostName|Domain|Name
win01|ad.dkfz-heidelberg.de|WIN01
12. Seite 1206.10.2010| Thomas Sesselmann ITCF
Check-Skript (check_wmi.pl)
Usage: ./check_wmi.pl [Options]* [check]
Options: (-h, -v, -d, -w, -c, -a, -t, --tmpdir)
-U, --user=<s> User with WMI-Read rights
-P, --password=<s> Password for User
-H, --host=<s> Host to query (Default: '')
--wmic=<s> wmic-command (Default: '/usr/…/wmic')
--delimiter=<s> delimiter for wmic (Default: '-xXx-')
Check:
CPULOAD - Gets (total) CPU load
DISKFREE - Free disk space
MEMFREE - Gets memory and pagefile usage
PROCS - Get number of running processes
RESGROUP - Gets MSCluster (resource group) status
SERVICE - Check service state
SYSTEM - Gets system name and uptime
USERS - Get number of connected users
VOLFREE - Free disk space (check volumes)
Hint:
Try to use 'check_wmi.pl -h [check]' to see the defaults for the
check!
13. Seite 1306.10.2010| Thomas Sesselmann ITCF
Beispiel check_wmi.pl system
$ check_wmi.pl -H win01 system
OK - System: win01, Microsoft(R) Windows(R)
Server 2003, Standard Edition, Service Pack 2
(Version: 5.2.3790), Installed 2003.11.06 (6
years 334 days ago), Up 12 days RAM: 3.7GB,
Pagefile: 1.8GB|uptime=1076058s
14. Seite 1406.10.2010| Thomas Sesselmann ITCF
Beispiel check_wmi.pl system --verbose
$ check_wmi.pl -H win01 system -v
Run Query 'SELECT Caption,CSDVersion,CSName,Version,InstallDate,
LastBootUpTime,LocalDateTime,Status,TotalVirtualMemorySize,
TotalVisibleMemorySize FROM Win32_OperatingSystem'
1>> Class: Win32_OperatingSystem
2>> Header
3>>
0 Caption = Microsoft(R) Windows(R) Server 2003, Standard Edition
1 CSDVersion = Service Pack 2
2 CSName = WIN01
3 InstallDate = 20031106113716.000000+060
4 LastBootUpTime = 20100922051838.125000+120
5 LocalDateTime = 20101004161259.191000+120
6 Name = Microsoft Windows Server 2003 R2 Standard
Edition|C:WINDOWS|DeviceHarddisk0Partition1
7 Status = OK
8 TotalVirtualMemorySize = 5869088
9 TotalVisibleMemorySize = 3931584
10 Version = 5.2.3790
OK - System: win01, Microsoft(R) Windows(R) Server 2003, Standard Edition,
Service Pack 2 (Version: 5.2.3790), Installed 2003.11.06 (6 years 334 days ago),
Up 12 days RAM: 3.7GB, Pagefile: ...1.8GB|uptime=1076058s
15. Seite 1506.10.2010| Thomas Sesselmann ITCF
PNP4Nagios (OSMC2009)
• http://pnp4nagios.org
• Verlaufsgrafiken gut für
• Erkennung von Trends
• Erkennung von Mustern
• Historie
Problem neu?
16. Seite 1606.10.2010| Thomas Sesselmann ITCF
check_wmi.pl … SYSTEM
• Class: Win32_OperatingSystem
• Attr: InstallDate, LastBootUpTime, Caption
OK - System: INFO, Microsoft(R) Windows(R) Server 2003,
Standard Edition, Service Pack 2 (Version: 5.2.3790),
Installed 2006.02.06 (4 years 241 days ago), Up 20 days
RAM: 2.0GB, Pagefile: 1.9GB|uptime=1752789s
17. Seite 1706.10.2010| Thomas Sesselmann ITCF
check_wmi.pl … PROCS
• Class: Win32_OperatingSystem
• Attr: NumberOfProcesses
OK - PROCS: 45 running Processes|procs=45;200;500;0;
18. Seite 1806.10.2010| Thomas Sesselmann ITCF
check_wmi.pl …USERS
• Class: Win32_OperatingSystem
• Attr: NumberOfUsers
OK - USERS: 7 connected user sessions
|users=7;200;500;0;
37. Seite 3706.10.2010| Thomas Sesselmann ITCF
Citrix-Terminalserver
• CLASS: Win32_PerfFormattedData_CitrixICA_ICASession
• Attr:
• LatencySessionAverage
• Name
38. Seite 3806.10.2010| Thomas Sesselmann ITCF
Eventlogs
• Problem sehr viele Einträge Timeout
• Filter notwendig
• Besser auslesen und in zentrale DB speichern
besser neues Skript
SELECT *
FROM Win32_NTLogEvent
WHERE Type="Error"
AND LogFile="System" AND
TimeGenerated > "20100629000000.000000+120"