Here's a simple script to That monitors log entries for VMWare Virtual Center ( Stored in the VCDB). It has similar functionality to the standard intellipool Log Monitor. It will Generate One alarm when a new batch of errors are detected( One or more ). After the alarm has been raise it updates the time pointer, as to not generate multiple alarms. -- ONLY ONE ALARM WILL BE GENERATED ---
Arguments - Scripts Requires the name of the DSN configured from the INM Gateway/Server to the Database.
**The Code can be modified to read from any other database by changing the SQL Query**
Thanks,
/jAzz
-- Suggestions/ Comments Welcome
CODE
--[[
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
--]]
----------------------------------------------------------------
--[[
Author: Jazz Alyxzander Turner-Baggs
Required INM version: 3.4 (Build 2894 or higher)
Date: June 30th , 2008
Description:
Monitors VMWare Virtual Infrastructure Database for Errors via ODBC connector. The script
stores the timestamp of the last known error to check for new errors in the DB. This behaves
just as a looping list script where,
Warning - A New Event Will Only Cause One Alarm.
**With slight modifications to the SQL Section this script can be used to monitor any logs stored in a Database**
Config:
The Script Requires a DSN be configured from the INM Server/gateway to the Database server.
Arguments:
DSN - DSN to Appropriate Database
--]]
----------------------------------------------------------------
-- This function is called by INM to retrieve a script configuration
function OnConfigure()
Config = LuaScriptConfigurator()
Config:SetAuthor("Jazz Alyxzander Turner-Baggs")
Config:SetDescription("Monitors VMWare Virtual Infrastructure Database for Errors")
Config:SetMinBuildVersion(4003)
Config:SetScriptVersion(1,2)
Config:AddArgument("DSN:","Required ODBC Datasource",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Reset:","If Set to 'TRUE', Previous Time Pointer Is deleted - ",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:SetEntryPoint("main")
return Config
end
function main()
----------------------------------------------------------------
-- VARS
----------------------------------------------------------------
-- Script Vars
clear = false
sDBdefault = 'VCDB'
-- Storage Vars
Storage = TLuaStorage:new();
sKey = ""
sScriptName = "ESXLog"
-- Time Vars
t = TLuaDateTime
-- Inital Time Reference to increase performance of Inital Run.
minTime = "2008-10-10 01:11:45.342"
tmpTime = ""
-- String to Numerical Month conversion table
t = { Jan= 1 , Feb=2, Mar=3, Apr=4, May=5, Jun=6, Jul=7, Aug=8, Sep=9, Oct=10, Nov=11, Dec=12 }
-- Error Vars
sErrorString=""
tErrors = {}
tErrors[0] = 0
ERRORS_DISPLAYED = 20
----------------------------------------------------------------
-- Initilize
----------------------------------------------------------------
sConnectString = GetArgument(0)
clear = GetArgument(1)
----------------------------------------------------------------
-- Storage Section
----------------------------------------------------------------
-- UID - Object Address
-- Key - Scriptname
if clear == true then
Storage:DeleteItem(GetObjectAddress(),sKey..sScriptName )
SetExitStatus("Script Reset", false)
return
end
if Storage:CreateItem(GetObjectAddress(),sKey..sScriptName ,minTime, string.len(minTime) ) == false then
print("PREV" , minTime)
_a = Storage:FindItem(GetObjectAddress(),sKey..sScriptName)
minTime= _a.m_pData
end
----------------------------------------------------------------
-- SQL Section
----------------------------------------------------------------
sQuery0 = "Select * from VPX_Event where Create_time > {ts '".. minTime .. "'} and (Category='error' or Category = 'warning' ) order by create_Time"
-- DB maintianence
db = TLuaDB()
if (db:Connect(sConnectString, TLuaDB.CLIENT_ODBC) == false) then
SetExitStatus("Error: Cannot Connect to Database \-\- COnnect String is incorrect", false)
return
end
if db:Execute(sQuery0)== false then
SetExitStatus("Execution Error: ".. db:GetErrorDescription(), false);
return
end
if db:ResultAvilable() == false then
SetExitStatus("Error: DB Query Returned No Rows", false)
return
end
-- Last Error
db:NextRow()
-- Row Iterator: Isolate Time stamp, Error, User and Host
-- Store in Error Table
while db:NextRow() do
tmp = db:GetCol(4)
__,__,__,month, day, time, year = string.find(tmp, "(%a+) (%a+) (%d+) (%d+:%d+:%d+) (%d+)")
tErrors[0] = tErrors[0] + 1
tmpTime = "'" .. year .. "-" ..t[month] .. "-" .. day .. " " .. time .. "'"
tErrors[ tErrors[0] ]= tmpTime .. "\t" .. db:GetCol(3) .." \t " .. db:GetCol(6) .. " \t " .. db:GetCol(10) .. "\n"
end
-- Check for Errors
if tErrors[0] > 0 then
sStatus = "The Following Errors Have been detected: \n"
max = tErrors[0]
min = 0
-- UpDate Time Pointer
__,__,data = string.find(tErrors[max], "'(.+)'")
Storage:UpdateItem(GetObjectAddress(),sKey..sScriptName ,data, string.len(data) )
-- Truncate Events to a Maximum of 20 Entries.
if (max > 20) then
min = max - ERRORS_DISPLAYED
sStatus = "Excess Errors Detected (" .. max .. ") Displaying last " .. ERRORS_DISPLAYED .." Entries: \n"
end
-- Build Error String
while max > min do
sStatus = sStatus .. tErrors[max]
max = max-1
end
SetExitStatus(sStatus, false)
else
SetExitStatus("No Errors Found", true)
end
end
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
--]]
----------------------------------------------------------------
--[[
Author: Jazz Alyxzander Turner-Baggs
Required INM version: 3.4 (Build 2894 or higher)
Date: June 30th , 2008
Description:
Monitors VMWare Virtual Infrastructure Database for Errors via ODBC connector. The script
stores the timestamp of the last known error to check for new errors in the DB. This behaves
just as a looping list script where,
Warning - A New Event Will Only Cause One Alarm.
**With slight modifications to the SQL Section this script can be used to monitor any logs stored in a Database**
Config:
The Script Requires a DSN be configured from the INM Server/gateway to the Database server.
Arguments:
DSN - DSN to Appropriate Database
--]]
----------------------------------------------------------------
-- This function is called by INM to retrieve a script configuration
function OnConfigure()
Config = LuaScriptConfigurator()
Config:SetAuthor("Jazz Alyxzander Turner-Baggs")
Config:SetDescription("Monitors VMWare Virtual Infrastructure Database for Errors")
Config:SetMinBuildVersion(4003)
Config:SetScriptVersion(1,2)
Config:AddArgument("DSN:","Required ODBC Datasource",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:AddArgument("Reset:","If Set to 'TRUE', Previous Time Pointer Is deleted - ",LuaScriptConfigurator.CHECK_NOT_EMPTY)
Config:SetEntryPoint("main")
return Config
end
function main()
----------------------------------------------------------------
-- VARS
----------------------------------------------------------------
-- Script Vars
clear = false
sDBdefault = 'VCDB'
-- Storage Vars
Storage = TLuaStorage:new();
sKey = ""
sScriptName = "ESXLog"
-- Time Vars
t = TLuaDateTime
-- Inital Time Reference to increase performance of Inital Run.
minTime = "2008-10-10 01:11:45.342"
tmpTime = ""
-- String to Numerical Month conversion table
t = { Jan= 1 , Feb=2, Mar=3, Apr=4, May=5, Jun=6, Jul=7, Aug=8, Sep=9, Oct=10, Nov=11, Dec=12 }
-- Error Vars
sErrorString=""
tErrors = {}
tErrors[0] = 0
ERRORS_DISPLAYED = 20
----------------------------------------------------------------
-- Initilize
----------------------------------------------------------------
sConnectString = GetArgument(0)
clear = GetArgument(1)
----------------------------------------------------------------
-- Storage Section
----------------------------------------------------------------
-- UID - Object Address
-- Key - Scriptname
if clear == true then
Storage:DeleteItem(GetObjectAddress(),sKey..sScriptName )
SetExitStatus("Script Reset", false)
return
end
if Storage:CreateItem(GetObjectAddress(),sKey..sScriptName ,minTime, string.len(minTime) ) == false then
print("PREV" , minTime)
_a = Storage:FindItem(GetObjectAddress(),sKey..sScriptName)
minTime= _a.m_pData
end
----------------------------------------------------------------
-- SQL Section
----------------------------------------------------------------
sQuery0 = "Select * from VPX_Event where Create_time > {ts '".. minTime .. "'} and (Category='error' or Category = 'warning' ) order by create_Time"
-- DB maintianence
db = TLuaDB()
if (db:Connect(sConnectString, TLuaDB.CLIENT_ODBC) == false) then
SetExitStatus("Error: Cannot Connect to Database \-\- COnnect String is incorrect", false)
return
end
if db:Execute(sQuery0)== false then
SetExitStatus("Execution Error: ".. db:GetErrorDescription(), false);
return
end
if db:ResultAvilable() == false then
SetExitStatus("Error: DB Query Returned No Rows", false)
return
end
-- Last Error
db:NextRow()
-- Row Iterator: Isolate Time stamp, Error, User and Host
-- Store in Error Table
while db:NextRow() do
tmp = db:GetCol(4)
__,__,__,month, day, time, year = string.find(tmp, "(%a+) (%a+) (%d+) (%d+:%d+:%d+) (%d+)")
tErrors[0] = tErrors[0] + 1
tmpTime = "'" .. year .. "-" ..t[month] .. "-" .. day .. " " .. time .. "'"
tErrors[ tErrors[0] ]= tmpTime .. "\t" .. db:GetCol(3) .." \t " .. db:GetCol(6) .. " \t " .. db:GetCol(10) .. "\n"
end
-- Check for Errors
if tErrors[0] > 0 then
sStatus = "The Following Errors Have been detected: \n"
max = tErrors[0]
min = 0
-- UpDate Time Pointer
__,__,data = string.find(tErrors[max], "'(.+)'")
Storage:UpdateItem(GetObjectAddress(),sKey..sScriptName ,data, string.len(data) )
-- Truncate Events to a Maximum of 20 Entries.
if (max > 20) then
min = max - ERRORS_DISPLAYED
sStatus = "Excess Errors Detected (" .. max .. ") Displaying last " .. ERRORS_DISPLAYED .." Entries: \n"
end
-- Build Error String
while max > min do
sStatus = sStatus .. tErrors[max]
max = max-1
end
SetExitStatus(sStatus, false)
else
SetExitStatus("No Errors Found", true)
end
end