LiebermanSoftware.ERPMMP.DBJobDataSourceType

LiebermanSoftware.ERPMMP.DBJobDataSourceType (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Event.Data

Member Modules:

ID Module Type TypeId RunAs 
DataSource DataSource Microsoft.Windows.TimedScript.EventProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
MaxJobLengthint$Config/MaxJobLength$MaxJobLength
TimeoutSecondsint$Config/TimeoutSeconds$TimeoutSeconds
IntervalSecondsint$Config/IntervalSeconds$IntervalSeconds
SQLPasswordstring$Config/SQLPassword$SQLPassword
SQLUserNamestring$Config/SQLUserName$SQLUserName

Source Code:

<DataSourceModuleType ID="LiebermanSoftware.ERPMMP.DBJobDataSourceType" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element minOccurs="1" default="300" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" default="300" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" name="DatabaseServer" type="xsd:string"/>
<xsd:element minOccurs="1" name="DatabaseName" type="xsd:string"/>
<xsd:element minOccurs="1" name="SQLUserName" type="xsd:string"/>
<xsd:element minOccurs="1" name="SQLPassword" type="xsd:string"/>
<xsd:element minOccurs="0" name="SecureInput" type="xsd:string"/>
<xsd:element minOccurs="1" name="EventOriginId" type="xsd:string"/>
<xsd:element minOccurs="1" name="PublisherId" type="xsd:string"/>
<xsd:element minOccurs="1" name="PublisherName" type="xsd:string"/>
<xsd:element minOccurs="1" name="Channel" type="xsd:string"/>
<xsd:element minOccurs="1" name="LoggingComputer" type="xsd:string"/>
<xsd:element minOccurs="1" name="EventNumber" type="xsd:string"/>
<xsd:element minOccurs="1" name="EventCategory" type="xsd:string"/>
<xsd:element minOccurs="1" name="EventLevel" type="xsd:string"/>
<xsd:element minOccurs="1" name="Description" type="xsd:string"/>
<xsd:element minOccurs="1" name="UserName" type="xsd:string"/>
<xsd:element minOccurs="1" name="MaxJobLength" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="SQLUserName" Selector="$Config/SQLUserName$" ParameterType="string"/>
<OverrideableParameter ID="SQLPassword" Selector="$Config/SQLPassword$" ParameterType="string"/>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="MaxJobLength" Selector="$Config/MaxJobLength$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DataSource" TypeID="Windows!Microsoft.Windows.TimedScript.EventProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>Job.vbs</ScriptName>
<Arguments>"$Config/DatabaseServer$" "$Config/DatabaseName$" $Config/MaxJobLength$</Arguments>
<ScriptBody><Script><![CDATA[
on error resume next
SetLocale("en-us")
Const adOpenStatic = 3
Const adLockOptimistic = 3

Function GenerateConnectionStr (server, db)
SecureInputStr = wscript.stdin.readline()
if (len(SecureInputStr) < 6) then
GenerateConnectionStr = "Provider=SQLOLEDB;Data Source='" & DBSource & "';Trusted_Connection=Yes;Initial Catalog='" + DBName + "';"
else
a = split(SecureInputStr, """ """)
UserName = right(a(0), len(a(0)) - 1)
Password = left(a(1), len(a(1)) - 1)
GenerateConnectionStr = "Provider=SQLOLEDB;Data Source='" & DBSource & "';Initial Catalog='" + DBName + "';" + "User Id='" + username + "';Password='" + password + "';"
end if
end Function

Function GetIncompleteJob(conection, oAPI)
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open "select * from dbo.tbl_BaseJobInfo where eBaseJobLastResult = 2", conection, adOpenStatic, adLockOptimistic

str = ""
strContent = ""
set oShell = CreateObject("WScript.Shell")
atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
offsetMin = cint(oShell.RegRead(atb))
nd = dateadd("n", offsetMin, now)

do until objRecordSet.EOF
date1 = cdate(objRecordSet("dtLastRunTimeUTC"))
if (Datediff("n", date1, nd) < BackStartTime) and (Datediff("n", date1, nd) > BackDuration) then
str = str + "JOB " & objRecordSet("idRowID") & " started at " & objRecordSet("dtLastRunTimeUTC") & " and didn't not finish yet!" + vbcrlf
For i = 0 To objRecordSet.Fields.Count -1
strContent = strContent + objRecordSet.Fields(i).Name + " : " + cstr(objRecordSet(objRecordSet.Fields(i).Name)) + vbcrlf
Next
end if
objRecordSet.movenext
loop

if str <> "" then
Set oBag = oAPI.CreateTypedPropertyBag(1)
oBag.AddValue "EventID" , 100
oBag.AddValue "PublisherName" , "Enterprise Random Password Manager MP"
oBag.AddValue "Channel" , "Job"
oBag.AddValue "EventLevel" , 1
oBag.AddValue "EventDescription" , str + vbcrlf + strContent
oAPI.AddItem oBag
else
Set oBag = oAPI.CreateTypedPropertyBag(1)
oBag.AddValue "EventID" , 0
oBag.AddValue "PublisherName" , "Enterprise Random Password Manager MP"
oBag.AddValue "Channel" , "Job"
oBag.AddValue "EventLevel" , 4
oAPI.AddItem oBag
end if

objRecordset.Close
End Function


Function GetAutorollJob(connection, oAPI)
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open "select * from dbo.tbl_BaseJobInfo where sComment LIKE 'Auto-roll%'", Connection, adOpenStatic, adLockOptimistic

BackStartTime = 10
BackEndTime = 5

str = ""
strContent = ""
set oShell = CreateObject("WScript.Shell")
atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
offsetMin = cint(oShell.RegRead(atb))
nd = dateadd("n", offsetMin, now)

do until objRecordSet.EOF
date1 = cdate(objRecordSet("dtNextRunTimeUTC"))
if (Datediff("n", date1, nd)< BackStartTime ) and (Datediff("n", date1, nd) > BackEndTime) and (objRecordSet("eBaseJobLastResult") <> 6) then
str = str + "Autoroll JOB " & objRecordSet("idRowID") & " started at " & objRecordSet("dtNextRunTimeUTC") & " and didn't not finish yet!" + vbcrlf
For i = 0 To objRecordSet.Fields.Count -1
strContent = strContent + objRecordSet.Fields(i).Name + " : " + cstr(objRecordSet(objRecordSet.Fields(i).Name)) + vbcrlf
Next
end if
objRecordSet.movenext
loop

if str <> "" then
Set oBag = oAPI.CreateTypedPropertyBag(1)
oBag.AddValue "EventID" , 100
oBag.AddValue "PublisherName" , "Enterprise Random Password Manager MP"
oBag.AddValue "Channel" , "Autoroll Job"
oBag.AddValue "EventLevel" , 1
oBag.AddValue "EventDescription" , str + vbcrlf + strContent
oAPI.AddItem oBag
else
Set oBag = oAPI.CreateTypedPropertyBag(1)
oBag.AddValue "EventID" , 0
oBag.AddValue "PublisherName" , "Enterprise Random Password Manager MP"
oBag.AddValue "Channel" , "Autoroll Job"
oBag.AddValue "EventLevel" , 4
oAPI.AddItem oBag
end if

objRecordset.Close
End Function

time1 = now()

Set objParameters = WScript.Arguments
DBSource = objParameters(0)
DBName = objParameters(1)
MaxJobLength = cint(objParameters(2))
BackStartTime = MaxJobLength + 5
BackDuration = MaxJobLength 'run this rule every 5 minutes


Set oAPI = CreateObject("MOM.ScriptAPI")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open GenerateConnectionStr(DBSource, DBName)

if err.number <> 0 then
Set oBag = oAPI.CreateTypedPropertyBag(1)
oBag.AddValue "EventID" , 0
oBag.AddValue "PublisherName" , "Enterprise Random Password Manager MP"
oBag.AddValue "Channel" , "Database Connection Failure"
oBag.AddValue "EventLevel" , 1
oAPI.AddItem oBag
else
GetAutorollJob objConnection,oAPI
GetIncompleteJob objConnection,oAPI
objConnection.Close
end if

oAPI.ReturnItems

oAPI.logscriptevent "ERPM - Job", 204, 4, "total = " + cstr(DateDiff("s", time1, now)) + " seconds"

]]></Script></ScriptBody>
<SecureInput>"$Config/SQLUserName$" "$Config/SQLPassword$"</SecureInput>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<EventOriginId>$Config/EventOriginId$</EventOriginId>
<PublisherId>$Config/PublisherId$</PublisherId>
<PublisherName>$Config/PublisherName$</PublisherName>
<Channel>$Config/Channel$</Channel>
<LoggingComputer>$Config/LoggingComputer$</LoggingComputer>
<EventNumber>$Config/EventNumber$</EventNumber>
<EventCategory>$Config/EventCategory$</EventCategory>
<EventLevel>$Config/EventLevel$</EventLevel>
<UserName>$Config/UserName$</UserName>
<Description>$Config/Description$</Description>
<Params/>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DataSource"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Event.Data</OutputType>
</DataSourceModuleType>