¥¹¥¯¥ê¥×¥È¤ÎºîÀ®£²
¡ãCactiµ¯Æ°¸å¤Î½é´üÀßÄê¡¡¥Æ¥ó¥×¥ì¡¼¥È¤ÎÀßÄê¡ä
¥¹¥¯¥ê¥×¥È¤ÏWindowsɸ½à¤Ç»È¤¨¤ëVBS¤ÇºîÀ®¤·¤Æ¤ß¤Þ¤¹¡£
¤Þ¤º¤Ï¼ê»Ï¤á¤Ëcacti¥µ¡¼¥Ð¡¼¤ÎCPU¾ðÊó¤ò¼èÆÀ¤·¤Æ¤ß¤Þ¤¹¡£
Win32_Processor¥ª¥Ö¥¸¥§¥¯¥È¤Î³Æ¥á¥½¥Ã¥É¤ò¼èÆÀ¤·¤Þ¤¹¡£
processor.vbs¤È¤·¤Æ°Ê²¼¤ÎÆâÍƤòµ½Ò¤·¤Þ¤¹¡£
1: 'ÊÑ¿ô¤ÎÀßÄê
2: strComputer = "localhost" '¥í¥°¥¤¥ó¤¹¤ë¥Û¥¹¥È
3: command="" '¼èÆÀ¥³¥Þ¥ó¥É
4: field="" '¼èÆÀ¥ª¥Ö¥¸¥§¥¯¥È
5: index=0 '¥¤¥ó¥Ç¥Ã¥¯¥¹
6: selected = -1 '¼èÆÀ¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹
7: Dim array(2) '¾õÂÖ¾ðÊóÊÝ»ýÍÑ
8:
9: '°ú¿ô¤Î²òÀÏ
10: Set args = Wscript.Arguments
11: If args.length > 0 Then
12: command = args(0)
13: If args(0) = "query" Then
14: field = args(1)
15: End If
16: If args(0) = "get" Then
17: field = args(1)
18: selected = args(2)
19: End If
20: End If
21:
22: 'WMI¥ª¥Ö¥¸¥§¥¯¥È¤ÎºîÀ®
23: 'localhost
24: Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
25:
26: '¥¯¥¨¥ê
27: Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor",,48)
28:
29: '¾õÂÖɽ¼¨
30: For Each objItem in colItems
31: array(0) = FormatNumber(index, 0, -1, 0, 0)
32: Select Case field
33: Case "Caption" array(1) = objItem.Caption
34: Case "CpuStatus" array(1) = objItem.CpuStatus
35: Case "Description" array(1) = objItem.Description
36: Case "LoadPercentage" array(1) = objItem.LoadPercentage
37: Case "Status" array(1) = objItem.Status
38: Case "ProcessorType"
39: Select Case objItem.ProcessorType
40: Case "1" array(1) = "Other"
41: Case "2" array(1) = "Unknown"
42: Case "3" array(1) = "CentralProcessor"
43: Case "4" array(1) = "MathProcessor"
44: Case "5" array(1) = "DSPProcessor"
45: Case "6" array(1) = "VideoProcessor"
46: End Select
47: End Select
48:
49: Select Case command
50: Case "index" Wscript.StdOut.Writeline array(0)
51: Case "query" Wscript.StdOut.Writeline array(0) & "!" & array(1)
52: Case "get" If selected = FormatNumber(index, 0, -1, 0, 0) Then Wscript.StdOut.Write array(1) End If
53: End Select
54: index = index + 1
55: Next
¤³¤ì¤òc:\cacti\scripts\WMI¥Õ¥©¥ë¥À¤Ë³ÊǼ¤·¤Þ¤¹¡£
¡ÊWMI¥Õ¥©¥ë¥À¤Ï¿·µ¬¤ËºîÀ®¤·¤Þ¤¹¡Ë
Æ°ºî¥Æ¥¹¥È¤ò¤·¤Þ¤¹¡£
¥³¥Þ¥ó¥É¥×¥í¥ó¥×¥È¤Çºî¶È¤·¤Þ¤¹¡£
°ú¿ô¤Ï¥³¥Þ¥ó¥É¡¢¼èÆÀ¤·¤¿¤¤¥á¥½¥Ã¥É̾¡¢¼èÆÀ¤·¤¿¤¤¾ðÊó¤ÎÈÖ¹æ¤È¤·¤Æ¤¤¤Þ¤¹¡£
¥³¥Þ¥ó¥É¤Ï°Ê²¼¤Î¼ïÎब¤¢¤ê¤Þ¤¹¡£
shell> cd c:\cacti\scripts\WMI
shell> cscript //b processor.vbs index
0
1
shell> cscript //b processor.vbs query Caption
0!x86 Family 6 Model 14 Stepping 8
1!x86 Family 6 Model 14 Stepping 8
shell> cscript //b processor.vbs query LoadPercentage
0!2
1!0
shell> cscript //b processor.vbs query LoadPercentage
0!2
1!0
shell> cscript //b processor.vbs get LoadPercentage 0
2
¥ê¥â¡¼¥È¤Î¥µ¡¼¥Ð¡¼¤Î¾ì¹ç¡¢24¹ÔÌܤÎWMI¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®Éôʬ¤¬°Û¤Ê¤ê¤Þ¤¹¡£
¥ê¥â¡¼¥È¥µ¡¼¥Ð¡¼¾å¤Ë¤¢¤ë´ÉÍý¼Ô¥¢¥«¥¦¥ó¥È¤È¥Ñ¥¹¥ï¡¼¥É¤ò»È¤Ã¤Æ¾ðÊó¤ò¼èÆÀ¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
2: strComputer = "localhost" '¥í¥°¥¤¥ó¤¹¤ë¥Û¥¹¥È
3: command="" '¼èÆÀ¥³¥Þ¥ó¥É
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¢
2: strComputer = "localhost" '¥í¥°¥¤¥ó¤¹¤ë¥Û¥¹¥È
3: strUser = "administrator" '¥í¥°¥¤¥ó¥¢¥«¥¦¥ó¥È
4: strPassword = "admin" '¥í¥°¥¤¥ó¥Ñ¥¹¥ï¡¼¥É
5: command="" '¼èÆÀ¥³¥Þ¥ó¥É
10: Set args = Wscript.Arguments
11: If args.length > 0 Then
12: command = args(0)
13: If args(0) = "query" Then
14: field = args(1)
15: End If
16: If args(0) = "get" Then
17: field = args(1)
18: selected = args(2)
19: End If
20: End If
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¢
10: Set args = Wscript.Arguments
11: strComputer = args(0)
12: strUser = args(1)
13: strPassword = args(2)
14: If args.length > 0 Then
15: command = args(3)
16: If args(3) = "query" Then
17: field = args(4)
18: End If
19: If args(3) = "get" Then
20: field = args(4)
21: selected = args(5)
22: End If
23: End If
23: 'localhost
24: Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¢
23: 'localhost
24: 'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
25: 'remote host
26: Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
27: Set objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\CIMV2", strUser, strPassword)
Æ°ºî¥Æ¥¹¥È¤ò¤·¤Þ¤¹¡£
shell> cd c:\cacti\scripts\WMI
shell> cscript //b processor.vbs remoteserver administrator password index
0
shell> cscript //b processor.vbs administrator password query LoadPercentage
0!2
shell> cscript //b processor.vbs administrator password query LoadPercentage
0!2
shell> cscript //b processor.vbs administrator password get LoadPercentage 0
2
¥í¡¼¥«¥ë¥µ¡¼¥Ð¡¼¤Ø¤Î¥¢¥¯¥»¥¹¤Ï¥æ¡¼¥¶¡¼¥¢¥«¥¦¥ó¥È¡¢¥Ñ¥¹¥ï¡¼¥É¤òÆþÎϤ¹¤ë¤È
shell> cscript //b processor.vbs localhost "" "" index
0
1
¡ãCactiµ¯Æ°¸å¤Î½é´üÀßÄê¡¡¥Æ¥ó¥×¥ì¡¼¥È¤ÎÀßÄê¡ä
¥¹¥¯¥ê¥×¥È¤ÏWindowsɸ½à¤Ç»È¤¨¤ëVBS¤ÇºîÀ®¤·¤Æ¤ß¤Þ¤¹¡£
¤Þ¤º¤Ï¼ê»Ï¤á¤Ëcacti¥µ¡¼¥Ð¡¼¤ÎCPU¾ðÊó¤ò¼èÆÀ¤·¤Æ¤ß¤Þ¤¹¡£
Win32_Processor¥ª¥Ö¥¸¥§¥¯¥È¤Î³Æ¥á¥½¥Ã¥É¤ò¼èÆÀ¤·¤Þ¤¹¡£
processor.vbs¤È¤·¤Æ°Ê²¼¤ÎÆâÍƤòµ½Ò¤·¤Þ¤¹¡£
1: 'ÊÑ¿ô¤ÎÀßÄê
2: strComputer = "localhost" '¥í¥°¥¤¥ó¤¹¤ë¥Û¥¹¥È
3: command="" '¼èÆÀ¥³¥Þ¥ó¥É
4: field="" '¼èÆÀ¥ª¥Ö¥¸¥§¥¯¥È
5: index=0 '¥¤¥ó¥Ç¥Ã¥¯¥¹
6: selected = -1 '¼èÆÀ¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹
7: Dim array(2) '¾õÂÖ¾ðÊóÊÝ»ýÍÑ
8:
9: '°ú¿ô¤Î²òÀÏ
10: Set args = Wscript.Arguments
11: If args.length > 0 Then
12: command = args(0)
13: If args(0) = "query" Then
14: field = args(1)
15: End If
16: If args(0) = "get" Then
17: field = args(1)
18: selected = args(2)
19: End If
20: End If
21:
22: 'WMI¥ª¥Ö¥¸¥§¥¯¥È¤ÎºîÀ®
23: 'localhost
24: Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
25:
26: '¥¯¥¨¥ê
27: Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor",,48)
28:
29: '¾õÂÖɽ¼¨
30: For Each objItem in colItems
31: array(0) = FormatNumber(index, 0, -1, 0, 0)
32: Select Case field
33: Case "Caption" array(1) = objItem.Caption
34: Case "CpuStatus" array(1) = objItem.CpuStatus
35: Case "Description" array(1) = objItem.Description
36: Case "LoadPercentage" array(1) = objItem.LoadPercentage
37: Case "Status" array(1) = objItem.Status
38: Case "ProcessorType"
39: Select Case objItem.ProcessorType
40: Case "1" array(1) = "Other"
41: Case "2" array(1) = "Unknown"
42: Case "3" array(1) = "CentralProcessor"
43: Case "4" array(1) = "MathProcessor"
44: Case "5" array(1) = "DSPProcessor"
45: Case "6" array(1) = "VideoProcessor"
46: End Select
47: End Select
48:
49: Select Case command
50: Case "index" Wscript.StdOut.Writeline array(0)
51: Case "query" Wscript.StdOut.Writeline array(0) & "!" & array(1)
52: Case "get" If selected = FormatNumber(index, 0, -1, 0, 0) Then Wscript.StdOut.Write array(1) End If
53: End Select
54: index = index + 1
55: Next
¤³¤ì¤òc:\cacti\scripts\WMI¥Õ¥©¥ë¥À¤Ë³ÊǼ¤·¤Þ¤¹¡£
¡ÊWMI¥Õ¥©¥ë¥À¤Ï¿·µ¬¤ËºîÀ®¤·¤Þ¤¹¡Ë
Æ°ºî¥Æ¥¹¥È¤ò¤·¤Þ¤¹¡£
¥³¥Þ¥ó¥É¥×¥í¥ó¥×¥È¤Çºî¶È¤·¤Þ¤¹¡£
°ú¿ô¤Ï¥³¥Þ¥ó¥É¡¢¼èÆÀ¤·¤¿¤¤¥á¥½¥Ã¥É̾¡¢¼èÆÀ¤·¤¿¤¤¾ðÊó¤ÎÈÖ¹æ¤È¤·¤Æ¤¤¤Þ¤¹¡£
¥³¥Þ¥ó¥É¤Ï°Ê²¼¤Î¼ïÎब¤¢¤ê¤Þ¤¹¡£
- index
- ¥¤¥ó¥Ç¥Ã¥¯¥¹¥ê¥¹¥È¤òɽ¼¨¤·¤Þ¤¹
- query
- »ØÄꤷ¤¿¥á¥½¥Ã¥É¤Î¾ðÊó¤ò¥¤¥ó¥Ç¥Ã¥¯¥¹ÃͤȤȤâ¤ËÎóµó¤·¤Þ¤¹
- get
- »ØÄꤵ¤ì¤¿¥á¥½¥Ã¥É¤Î¤¦¤Á»ØÄꤵ¤ì¤¿ÈÖ¹æ¤Î¾ðÊó¤Î¤ß¤òɽ¼¨¤·¤Þ¤¹
shell> cd c:\cacti\scripts\WMI
shell> cscript //b processor.vbs index
0
1
shell> cscript //b processor.vbs query Caption
0!x86 Family 6 Model 14 Stepping 8
1!x86 Family 6 Model 14 Stepping 8
shell> cscript //b processor.vbs query LoadPercentage
0!2
1!0
shell> cscript //b processor.vbs query LoadPercentage
0!2
1!0
shell> cscript //b processor.vbs get LoadPercentage 0
2
¥ê¥â¡¼¥È¤Î¥µ¡¼¥Ð¡¼¤Î¾ì¹ç¡¢24¹ÔÌܤÎWMI¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®Éôʬ¤¬°Û¤Ê¤ê¤Þ¤¹¡£
¥ê¥â¡¼¥È¥µ¡¼¥Ð¡¼¾å¤Ë¤¢¤ë´ÉÍý¼Ô¥¢¥«¥¦¥ó¥È¤È¥Ñ¥¹¥ï¡¼¥É¤ò»È¤Ã¤Æ¾ðÊó¤ò¼èÆÀ¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
2: strComputer = "localhost" '¥í¥°¥¤¥ó¤¹¤ë¥Û¥¹¥È
3: command="" '¼èÆÀ¥³¥Þ¥ó¥É
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¢
2: strComputer = "localhost" '¥í¥°¥¤¥ó¤¹¤ë¥Û¥¹¥È
3: strUser = "administrator" '¥í¥°¥¤¥ó¥¢¥«¥¦¥ó¥È
4: strPassword = "admin" '¥í¥°¥¤¥ó¥Ñ¥¹¥ï¡¼¥É
5: command="" '¼èÆÀ¥³¥Þ¥ó¥É
10: Set args = Wscript.Arguments
11: If args.length > 0 Then
12: command = args(0)
13: If args(0) = "query" Then
14: field = args(1)
15: End If
16: If args(0) = "get" Then
17: field = args(1)
18: selected = args(2)
19: End If
20: End If
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¢
10: Set args = Wscript.Arguments
11: strComputer = args(0)
12: strUser = args(1)
13: strPassword = args(2)
14: If args.length > 0 Then
15: command = args(3)
16: If args(3) = "query" Then
17: field = args(4)
18: End If
19: If args(3) = "get" Then
20: field = args(4)
21: selected = args(5)
22: End If
23: End If
23: 'localhost
24: Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¢
23: 'localhost
24: 'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
25: 'remote host
26: Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
27: Set objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\CIMV2", strUser, strPassword)
Æ°ºî¥Æ¥¹¥È¤ò¤·¤Þ¤¹¡£
shell> cd c:\cacti\scripts\WMI
shell> cscript //b processor.vbs remoteserver administrator password index
0
shell> cscript //b processor.vbs administrator password query LoadPercentage
0!2
shell> cscript //b processor.vbs administrator password query LoadPercentage
0!2
shell> cscript //b processor.vbs administrator password get LoadPercentage 0
2
¥í¡¼¥«¥ë¥µ¡¼¥Ð¡¼¤Ø¤Î¥¢¥¯¥»¥¹¤Ï¥æ¡¼¥¶¡¼¥¢¥«¥¦¥ó¥È¡¢¥Ñ¥¹¥ï¡¼¥É¤òÆþÎϤ¹¤ë¤È
SWbemLocator: ¥æ¡¼¥¶¡¼»ñ³Ê¾ðÊó¤Ï¥í¡¼¥«¥ëÀܳ¤Ë¤Ï»ÈÍѤǤ¤Þ¤»¤ó¤È¤Ï¤Í¤é¤ì¤Æ¤·¤Þ¤¦¤Î¤Ç¡¢¥¢¥«¥¦¥ó¥È¡¢¥Ñ¥¹¥ï¡¼¥É¤Ë¶õʸ»úÎó""¤ò»ØÄꤷ¤Þ¤¹¡£
shell> cscript //b processor.vbs localhost "" "" index
0
1
¡ãCactiµ¯Æ°¸å¤Î½é´üÀßÄê¡¡¥Æ¥ó¥×¥ì¡¼¥È¤ÎÀßÄê¡ä
2007ǯ11·î09Æü(¶â) 01:06:27 Modified by slt33333