Advertisement
Advertisement
| 05.14.2008 at 03:12PM PDT, ID: 23403375 |
|
[x]
Attachment Details
|
||
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 05.14.2008 at 03:43PM PDT, ID: 21569309 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: |
'==========================================================================
'
' VBScript Source File
'
' NAME: bb-sqlserver.vbs
'
' AUTHOR: Oliver Bassett , gen-i
' DATE : 20/09/2003
'
' MODIFIED: Paul Tormey, Fisher & Paykel Appliances
' Installed on MAO in "C:\Program Files\Hobbit Monitor Feed\bb-sqlserver.vbs"
'
' COMMENT: This script will check a range or parameters in SQL server
' via it's windows performance counters using WMI. It will then Warn
' or Alarm as configured and report the information back to the
' configured Big Brother Server. You require the Big Brother client
' to be already installed.
'
' NOTES: You may need to change the extPath setting which currently tries
' to read the Professional Edition Client Reg Key.
'
' LICENSE:
' Copyright (c) 2003, Gen-i Limited
' All rights reserved.
'
' Redistribution and use in source and binary forms, with or without
' modification, are permitted provided that the following conditions are met:
'
' - Redistributions of source code must retain the above copyright notice,
' this list of conditions and the following disclaimer.
' - Redistributions in binary form must reproduce the above copyright notice,
' this list of conditions and the following disclaimer in the documentation
' and/or other materials provided with the distribution.
' - Neither the name of Gen-i Limited nor the names of its contributors
' may be used to endorse or promote products derived from this software without
' specific prior written permission.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
' EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
' OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
' SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
' SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
' OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
' HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
' TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
' EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'
' VERSION HISTORY:
' 0.1 - Initial Release
' 0.2 - Fixed UserConnections which were using the settings from
' Deadlocks rather than their own Warn/Alarm values
' Thanks to Erik Damsgaard, CSC Managed Web Services
' For pointing this out
'==========================================================================
strAlarmState = "green"
strTestName = "MAO"
'Physical Disk Settings
'% Disk Read Time
iPerDiskReadTimeWarn=5
iPerDiskReadTimeAlarm=10
'% Disk Write Time
iPerDiskWriteTimeWarn=5
iPerDiskWriteTimeAlarm=10
'Current Disk Queue Length
iCurDiskQueueLengthWarn=10
iCurDiskQueueLengthAlarm=20
'SQL Buffer Cache Hit Ratio
iBufferCacheHitRatioWarn=90
iBufferCacheHitRatioAlarm=85
'SQL Lock Timeouts /sec
iLockTimeoutsWarn=50
iLockTimeoutsAlarm=100
'SQL Dead Locks /sec
iDeadLocksWarn=2
iDeadLocksAlarm=5
'User Connections
iUserConnectionsWarn=30
iUserConnectionsAlarm=70
'SQL Data and Log Files (KB)
'These settings are stored in an associative array per database and then all these
'associative arrays are stored in a Main one.
'To add a new set of database logs to be monitored:
'1. Create an Associative Array for it: Set a[DatabaseName]DatabaseSetting = CreateObject("scripting.dictionary")
'2. Add the warning and alarm levels for the monitoring: a[DatabaseName]DatabaseSetting.add "DataFileWarn", 10000
' The above will add a warning for the Data file and set it at 10000KB.
' You will need to add warnings and alarms for both the data file and the log file.
'3. Next you need to add this to the main array.
' The format is: aSQLDataFileSettings.add "[DatabaseName]", a[DatabaseName]DatabaseSetting
'
' Thats it, it should just work now.
' Master Database Settings
Set aMasterDatabaseSetting = CreateObject("scripting.dictionary")
aMasterDatabaseSetting.add "DataFileWarn", 15000
aMasterDatabaseSetting.add "DataFileAlarm", 20000
aMasterDatabaseSetting.add "LogFileWarn", 2000
aMasterDatabaseSetting.add "LogFileAlarm", 4000
' Model Database Settings
Set aModelDatabaseSetting = CreateObject("scripting.dictionary")
aModelDatabaseSetting.add "DataFileWarn", 15000
aModelDatabaseSetting.add "DataFileAlarm", 20000
aModelDatabaseSetting.add "LogFileWarn", 2000
aModelDatabaseSetting.add "LogFileAlarm", 4000
'Main Array
SET aSQLDataFileSettings = CreateObject("scripting.dictionary")
aSQLDataFileSettings.add "master", aMasterDatabaseSetting
aSQLDataFileSettings.add "model", aModelDatabaseSetting
Const EVENT_SUCCESS = 0
strOutput = ""
Set ws = WScript.CreateObject("WScript.Shell")
extPath = ws.RegRead("HKLM\SOFTWARE\Quest Software\BigBrother\bbnt\ExternalPath\")
Set objShell = Wscript.CreateObject("Wscript.Shell")
' ========================================
' Main Code Starts Here
'Physical Disk
Set colDisk = GetObject("winmgmts:").InstancesOf("Win32_PerfRawData_PerfDisk_PhysicalDisk")
strOutput = strOutput & vbcrlf &"Physical Disk Information:" & vbCrLf
' Write Events to the Local Event Log
objShell.LogEvent EVENT_SUCCESS, _
"bb-sqlserver Hobbit feeder"
For each DiskInstance in ColDisk
'% Disk Read Time
strOutput = strOutput & CheckValue(GetWMIPercent("Win32_PerfRawData_PerfDisk_PhysicalDisk.Name","""" & DiskInstance.Name & """","PercentDiskReadTime","PercentDiskReadTime_Base"),DiskInstance.name & " % Disk Read Time",iPerDiskReadTimeWarn,iPerDiskReadTimeAlarm)
'% Disk Write Time
strOutput = strOutput & CheckValue(GetWMIPercent("Win32_PerfRawData_PerfDisk_PhysicalDisk.Name","""" & DiskInstance.Name & """","PercentDiskWriteTime","PercentDiskWriteTime_Base"),DiskInstance.name & " % Disk Write Time",iPerDiskWriteTimeWarn,iPerDiskWriteTimeAlarm)
'Current Disk Queue Length
strOutput = strOutput & CheckValue(GetWMIValue("Win32_PerfRawData_PerfDisk_PhysicalDisk.Name","""" & DiskInstance.Name & """","CurrentDiskQueueLength"),DiskInstance.name & " Current Disk Queue Length",iCurDiskQueueLengthWarn,iCurDiskQueueLengthAlarm)
Next
' SQL Server
strOutput = strOutput & vbcrlf & "SQL Server Information:" & vbcrlf
'Buffer Cache Hit Ration
strOutput = strOutput & CheckReverseValue(GetWMIPercent("Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager","@","Buffercachehitratio","Buffercachehitratio_Base"),"Buffer Cache Hit Ratio",iBufferCacheHitRatioWarn, iBufferCacheHitRatioAlarm)
'Lock Information
strOutput = strOutput & CheckValue(GetWMIValue("Win32_PerfRawData_MSSQLSERVER_SQLServerLocks.Name","""_Total""","LockTimeoutsPersec"),"Locks Timeouts/sec",iLockTimeoutsWarn, iLockTimeoutsAlarm)
strOutput = strOutput & CheckValue(GetWMIValue("Win32_PerfRawData_MSSQLSERVER_SQLServerLocks.Name","""_Total""","NumberofDeadlocksPersec"),"Number of Deadlocks/sec",iDeadLocksWarn, iDeadLocksAlarm)
'User Connections
strOutput = strOutput & CheckValue(GetWMIValue("Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics","@","UserConnections"),"Number of User Connections",iUserConnectionsWarn, iUserConnectionsAlarm)
'SQL Data and Log Files
Set colDatabases = GetObject("winmgmts:").InstancesOf("Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases")
strOutput = strOutput & vbcrlf & "SQL Server Data and Log File Information:" & vbcrlf
For each DatabaseInstance in colDatabases
If aSQLDataFileSettings.exists(DatabaseInstance.name) then
'Check Values
strOutput = strOutput & CheckValue(GetWMIValue("Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases","""" & DatabaseInstance.name & """","DataFilesSizeKB"),DatabaseInstance.name & vbTab & "Data File Size(KB)",aSQLDataFileSettings.item(DatabaseInstance.name).item("DataFileWarn"), aSQLDataFileSettings.item(DatabaseInstance.name).item("DataFileAlarm"))
strOutput = strOutput & CheckValue(GetWMIValue("Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases","""" & DatabaseInstance.name & """","LogFilesSizeKB"),DatabaseInstance.name & vbTab & "Log File Size(KB)",aSQLDataFileSettings.item(DatabaseInstance.name).item("LogFileWarn"), aSQLDataFileSettings.item(DatabaseInstance.name).item("LogFileAlarm"))
strOutput = strOutput & vbcrlf
elseif DatabaseInstance.Name = "_Total" then
' Skipping Display of Totals at this stage. May re-add later
' strOutput = strOutput & vbcrlf & "Total Data File Size:" & vbTab & GetWMIValue("Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases.Name","""" & DatabaseInstance.name & """","DataFilesSizeKB") & vbcrlf
' strOutput = strOutput & vbcrlf & "Total Log File Size:" & vbTab & GetWMIValue("Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases.Name","""" & DatabaseInstance.name & """","LogFilesSizeKB") & vbcrlf
else
' Write Data Information Directly Out without running the Value Check
' Datafile
strOutput = strOutput & "&clear" & " " & DatabaseInstance.name & vbTab & "Data File Size(KB)" & ":" & vbTab & GetWMIValue("Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases.Name","""" & DatabaseInstance.name & """","DataFilesSizeKB") & vbcrlf
' Logfile
strOutput = strOutput & "&clear" & " " & DatabaseInstance.name & vbTab & "Log File Size(KB)" & ":" & vbTab & GetWMIValue("Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases.Name","""" & DatabaseInstance.name & """","LogFilesSizeKB") & vbcrlf
strOutput = strOutput & vbcrlf
end if
Next
' Write the file for BB
WriteFile extPath, strTestName, strAlarmState, strOutput
'===========================================================
' FUNCTIONS and SUBS start here
' This is used to get a percentage value from WMI. It requires the value and the base objects.
' It then returns the percentage
FUNCTION GetWMIPercent(strCollection,strInstance,strObject,strBaseObject)
' Write Events to the Local Event Log
objShell.LogEvent EVENT_SUCCESS, _
"bb-sqlserver Hobbit feeder: " & vbCrLf & "strCollection = " & strCollection & vbCrLf & "strInstance = " & strInstance
SET counterCollection = GETOBJECT("winmgmts:" & strCollection & "=" & strInstance)
FOR EACH cntproperty IN counterCollection.properties_
IF cntproperty.name = strObject THEN
iObjectValue = cntproperty
ELSEIF cntproperty.name = strBaseObject THEN
iObjectBaseValue = cntproperty
END IF
NEXT
GetWMIPercent = ROUND(CDBL(iObjectValue) / CDBL(iObjectBaseValue) * CDBL(100),0)
END FUNCTION
' This is used to pull a value from WMI.
FUNCTION GetWMIValue(strCollection,strInstance,strObject)
Set counterCollection = GetObject("winmgmts:" & strCollection & "=" & strInstance)
FOR EACH cntproperty IN counterCollection.properties_
IF cntproperty.name = strObject THEN
iObjectValue = cntproperty
END IF
NEXT
GetWMIValue = iObjectValue
END FUNCTION
' This is used to check the actual value against the warning and alarm.
FUNCTION CheckValue(iObjectValue,strObjectDesc,iWarnValue,iAlarmValue)
IF iWarnValue > iAlarmValue THEN
CheckValue = "&red" & " " & strObjectDesc & ":" & vbTab & "Object is Misconfigured"
IF strAlarmState <> "red" THEN
strAlarmState = "red"
END IF
ELSE
IF iObjectValue > iWarnValue THEN
IF iObjectValue > iAlarmValue THEN
CheckValue = "&red" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbcrlf
SetAlarmStatus "red"
ELSE
CheckValue = "&yellow" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbcrlf
SetAlarmStatus "yellow"
END IF
ELSE
CheckValue = "&green" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbcrlf
END IF
END IF
END FUNCTION
' This is used to check the actual value against the warning and alarm.
' This one the alarm will be a lower value than the warning. (Values Decrease rather than increase)
FUNCTION CheckReverseValue(iObjectValue,strObjectDesc,iWarnValue,iAlarmValue)
IF iWarnValue < iAlarmValue THEN
CheckReverseValue = "&red" & " " & strObjectDesc & ":" & vbTab & "Object is Misconfigured"
IF strAlarmState <> "red" THEN
strAlarmState = "red"
END IF
ELSE
IF iObjectValue < iWarnValue THEN
IF iObjectValue < iAlarmValue THEN
CheckReverseValue = "&red" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbcrlf
SetAlarmStatus "red"
ELSE
CheckReverseValue = "&yellow" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbcrlf
SetAlarmStatus "yellow"
END IF
ELSE
CheckReverseValue = "&green" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbcrlf
END IF
END IF
END FUNCTION
' This is called to set the overall alarm status.
SUB SetAlarmStatus(strnewAlarmState)
IF strnewAlarmState = "red" THEN
strAlarmState = strnewAlarmState
ELSEIF strnewAlarmState = "yellow" THEN
IF strAlarmState <> "red" THEN
strAlarmState = strnewAlarmState
END IF
END IF
END SUB
' This SUB is used for outputting the file to the external's directory in bb
SUB WriteFile(strExtPath, strTestName, strAlarmState, strOutput)
Set fso = CreateObject("Scripting.FileSystemObject")
strOutput = strAlarmState & " " & Date & " " & Time & vbcrlf & vbcrlf & strOutput & vbcrlf
Set f = fso.OpenTextFile(strExtPath & "\" & strTestName , 8 , TRUE)
f.Write strOutput
f.Close
Set fso = Nothing
END SUB
|
| 05.14.2008 at 04:18PM PDT, ID: 21569479 |
| 05.14.2008 at 05:12PM PDT, ID: 21569724 |
| 05.14.2008 at 05:23PM PDT, ID: 21569774 |
| 05.14.2008 at 05:40PM PDT, ID: 21569831 |
| 05.14.2008 at 05:51PM PDT, ID: 21569855 |
| 05.14.2008 at 06:36PM PDT, ID: 21570036 |
| 05.14.2008 at 06:39PM PDT, ID: 21570051 |
| 05.14.2008 at 07:31PM PDT, ID: 21570246 |
| 05.14.2008 at 07:46PM PDT, ID: 21570328 |
| 05.14.2008 at 07:50PM PDT, ID: 21570351 |
| 05.14.2008 at 07:52PM PDT, ID: 21570359 |
| 05.14.2008 at 07:55PM PDT, ID: 21570373 |
| 05.16.2008 at 04:50PM PDT, ID: 21587253 |
| 05.28.2008 at 06:22PM PDT, ID: 21665650 |