Last Updated on 2013年6月7日 by かんりにん
何気にLINUX PACKAGE SEARCHでwmi(Windows Management Instrumentation)の
RPMパッケージが紹介されていたので、空き時間に入れて試してみる。難易度は低く、試しやすい。
- RPMの配布元サイト
atomicorp
http://www.atomicorp.com/
Atomic Secured Linux という監視ツールもライセンス販売している様子。
- i386(32bit)
http://pkgs.org/centos-6-rhel-6/atomic-i386/wmi-1.3.14-2.el6.art.i686.rpm.html - x86_64(64bit)
wmi-1.3.14-2.el6.art.x86_64.rpm
http://pkgs.org/centos-6-rhel-6/atomic-x86_64/wmi-1.3.14-2.el6.art.x86_64.rpm.html
手順
直接RPMパッケージを落としてきて入れるのもありだが
atomic-releaseを入れてyumでリポジトリから入れる流れでやってみる。
配布元サイトにインストール手順があるので、そのままトレースしてみる。
- atomic-release
# wget http://www6.atomicorp.com/channels/atomic/centos/6/i386/RPMS/atomic- release-1.0-14.el6.art.noarch.rpm # rpm -Uvh atomic-release-1.0-14.el6.art.noarch.rpm warning: atomic-release-1.0-14.el6.art.noarch.rpm: Header V3 DSA/SHA1 Signature, ke y ID 5ebd2744: NOKEY Preparing... ########################################### [100%] 1:atomic-release ########################################### [100%]
- wmiインストール
# yum install wmi Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile * atomic: www2.atomicorp.com * epel: ftp.jaist.ac.jp Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package wmi.x86_64 0:1.3.14-2.el6.art will be installed --> Finished Dependency Resolution --- 中略 Total download size: 7.6 M Installed size: 36 M Is this ok [y/N]: y ←yを入力してインストール開始。
途中で"検証用のGPG-KEYが無いよ"警告がでるので、そのまま"y"を入力してインポートしておく。
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5ebd2744: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY.art.txt Importing GPG key 0x5EBD2744: Userid : Atomic Rocket Turtle <admin@atomicrocketturtle.com> Package: atomic-release-1.0-14.el6.art.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY.art.txt Is this ok [y/N]: y ←yを入力してGPGキーをインポート。
そのままインストール再開。
Installing : wmi-1.3.14-2.el6.art.x86_64 1/1 Installed: wmi.x86_64 0:1.3.14-2.el6.art Complete!
以上でインストール完了。
試しに使ってみる
実行ファイルwmicは
/bin/wmic
としてインストールされているので、直接実行。
コマンドとオプション
manは無いので、ヘルプで書式とコマンドオプションを見てみる。
- ヘルプ抜粋
# 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"
ひとまず書式例に合わせてやってみる。
- 書式
Example: wmic -U [domain/]adminuser%password //host "select * from Win32_ComputerSystem"
コマンド実行例と結果
Windowsドメイン"HOGEDOMAIN"内にあるファイルサーバー"FILESVR"へインベントリを取得する例。
# wmic -U HOGEDOMAIN/administrator%HOGEPASSWD //FILESVR "select * from Win32_ ComputerSystem" [実行結果] CLASS: Win32_ComputerSystem AdminPasswordStatus|AutomaticManagedPagefile|AutomaticResetBootOption|Autom aticResetCapability|BootOptionOnLimit|BootOptionOnWatchDog|BootROMSupported| BootupState|Caption|ChassisBootupState|CreationClassName|CurrentTimeZone|Da ylightInEffect|Description|DNSHostName|Domain|DomainRole|EnableDaylightSavingsT ime|FrontPanelResetStatus|InfraredSupported|InitialLoadInfo|InstallDate|KeyboardPa sswordStatus|LastLoadInfo|Manufacturer|Model|Name|NameFormat|NetworkServerM odeEnabled|NumberOfLogicalProcessors|NumberOfProcessors|OEMLogoBitmap|OEMStr ingArray|PartOfDomain|PauseAfterReset|PCSystemType|PowerManagementCapabilities |PowerManagementSupported|PowerOnPasswordStatus|PowerState|PowerSupplyState |PrimaryOwnerContact|PrimaryOwnerName|ResetCapability|ResetCount|ResetLimit|Roles |Status|SupportContactDescription|SystemStartupDelay|SystemStartupOptions|System StartupSetting|SystemType|ThermalState|TotalPhysicalMemory|UserName|WakeUpTyp e|Workgroup 3|True|True|True|0|0|True|Normal boot|FILESVR|3|Win32_ComputerSystem|540|False |AT/AT COMPATIBLE|filesvr01|localdomain.local|3|True|3|False|NULL|(null)|3|(null)|HP|Pro Liant DL180 G5|FILESVR|(null)|True|4|1|NULL|NULL|True|-1|1|NULL|False|3|0|3|(null) |Windows ユーザー|1|-1|-1|(LM_Workstation,LM_Server,SQLServer,NT,Server_NT)|OK|N ULL|0|NULL|0|X86-based PC|3|2145869824|LOCALDOMAN\administrator|6|(null)
パイプで区切られているのみで、横長なので
エクセルなどに落とす際はsedでタブに変換するなど編集作業がいると思われ。
また実行時に指定するクエリの種類を調べて、いろいろ試してみるのはあり。
パラメータを指定して実行してみた例
とりあえずサーバーに搭載された物理メモリの値だけ見てみる。
搭載容量は2GB。
# wmic -U HOGEDOMAIN/administrator%HOGEPASSWD //FILESVR "select TotalPhysicalMemory from Win32_ComputerSystem" [実行結果] CLASS: Win32_ComputerSystem Name|TotalPhysicalMemory FILESVR|2145869824
取得結果をDBへ格納&phpで簡単なUIなどを作成して
ちょっとした資産管理ができればOKか。