I decided that I could work with what information I had.
Here is how I am receiving my notifications.
1. For starters I found what query will return our current total users
The sql query for finding out how many users we have is as follows, which I saved to a file called besusertotal.sql
Code:
USE {besdatabase}
SELECT COUNT(*) AS TOTAL_USERS
FROM UserStats 2. Next there is a tool from Microsoft called SQLCMD so here is the command for running the query and returning the result
Code:
c:\sqlcmd -S {besserver} -i besusertotal.sql 3. This returns the output as follows:
Code:
Changed database context to '{besdatabase}'.
TOTAL_Users
-----------
717
(1 rows affected) 4. Ran the sqlcmd from a vbscript
:
Code:
Set objShell = WScript.CreateObject("WScript.Shell")
Dim arrQueryOutput(5), strCurrentUserTotal
Set objWshScriptExec = objShell.exec ("sqlcmd -S {besdatabase} -i beslicensequery.sql")
SET objOutput = objWshScriptExec.Stdout
While not objOutput.AtEndOfStream
arrQueryOutput(i) = objOutput.ReadLine
i = i + 1
WEnd
'The following line will put line number 4 (starts at 0 "zero") into my string
'so that I can run math on it later
strCurrentUserTotal = arrQueryOutput(3)
'The strCurrentLicenseTotal is our current number of licenses, unforutnately
'This piece of informatin is not anywhere in the database so it will have to
'be updated manually, not a big issue because I am notified when licenses
'are added to the BES
strCurrentLicenseTotal = 737
strAvailableLicenses = strCurrentLicenseTotal - strCurrentUserTotal 5. Because SMTP is installed on the computer running the script, I put strAvailableLicenses variable into an e-mail and the script mails it off
Code:
If strAvailableLicenses < 10 Then
Dim strFrom, strTo, strCC, strSubject, strTextBody
WScript.Echo "Sending E-mail"
strTo = "e-mail addresses"
strCC = "e-mail addresses"
strSubject = "BES Licenses LOW !!"
strTextbody = strNewContents
SendmailNoAttach
End If
Sub SendMailNoAttach
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "e-mail address"
objEmail.To = strTo
objEmail.CC = strCC
objEmail.ReplyTo = "e-mail address"
objEmail.Subject = strSubject
objEmail.Textbody = strTextBody
objEmail.Send
End Sub Set the script to run as a scheduled task and thats it. Once the available license total reaches below 10, Zing goes an e-mail
I hope this helps anyone who is looking for automatic license notification. If I have completely missed something easier, please let me know
Z