| | | Forum Guru
       
Group: Forum Members Last Login: 9/18/2008 7:15:13 AM Posts: 71, Visits: 177 |
| Hey out there,
yesterday somebody ask me how to add the message, a script returns to the statuspage, to the email generated by the action. I worked a bit with the device attributes and an idea comes to my mind. A few minutes later I had the script ready to work I started this extra topic, because topics like "Disk Space Monitor" often do not get a hit 
With the percent placeholders that are used in the "Email Action Options" (When you edit the content) you can access the Device Attributes. With %Device.Attribute.[AttributeName] maybe %Device.Attribute.Contact (as described in the manual on page 115) you are able to acces the value of the Attribute "Contact". So there is the option to build a bridge from your monitorscript to the email text. You only have to build a small codesnippet that puts the last statustext into this attribute.
Here is my snippet, remember that some parts of that snippet often are allready provided by your script eg. DB connection, deviceID and so on, so have a look at and edit. Do not forget to set the Status text that is set to Context.SetResult(1,"ERROR") to err="ERROR", too.
// Set the result code of the check (0=Success, 1=Error)
Context.SetResult( 0, "No error");
var err;
err = "No Error";
// WUP Database connect
var oDb = Context.GetDB;
if (null == oDb) {
result = false;
err += "WUP DB inaccessible! ";
} else {
// Get DeviceID
var deviceID = Context.GetProperty("DeviceID");
// Check if the Attribute STATUS is Allready provided
var sSql1 = "SELECT sValue FROM DeviceAttribute WHERE nDeviceID = " + deviceID + " AND sName LIKE 'STATUS'";
var statusrs = oDb.Execute(sSql1);
if(!statusrs.EOF) {
// Attribute is available
} else {
// Create Attribute
var sSql2 = "INSERT INTO DeviceAttribute (nDeviceID,sName,sValue) VALUES('"+deviceID+"','STATUS','"+err+"')";
oDb.Execute(sSql2);
}
var sSql3 = "UPDATE DeviceAttribute SET sValue = '"+err+"' WHERE nDeviceID = " + deviceID + " AND sName LIKE 'STATUS'";
oDb.Execute(sSql3);
oDb.Close();
statusrs.Close();
This script now creates the attribute if it is not allready available. Then the last statuscode is added. The %Device.Attribute.STATUS inside your mailsetting should then provide the last status (i've only tried until that point where the attribute is created and value is setted).
Have fun with that [Smile] Greetings from Sunny Germany
Jan |
| | | | Forum Member
       
Group: Forum Members Last Login: 6/20/2008 5:33:31 AM Posts: 38, Visits: 160 |
| Hi stanley
It's still me lol
To start, thanks for all this help about what's up   
I don't understant where you have to put this script, and what the problem with err
I put it at the end of a script but it doesn't work ( it's JSCRIPT or VBSCRIPT ??? )
Greetings |
| | | | Forum Guru
       
Group: Forum Members Last Login: 9/18/2008 7:15:13 AM Posts: 71, Visits: 177 |
| Hey ghost, this is actually JScript and only works with active scripts written in javascript. The codesnippet have to be placed after all checks but before the status is setted up. Below is a example with a Diskmonitor, to provide the information which drive causes the error inside the Email.
I Added some extra Information with //// starting.
// Get the Open DB connection from the Context NameSpace
var oDb = Context.GetDB;
if (null == oDb) {
Context.SetResult( 1, " Problem creating the DB object");
}
else {
// Variable to hold error message
var oDisplay = "Failure: ";
// Variable to determinate if we encountered an alarm
var bAlarm = false;
// Get the device ID
var nDeviceID = Context.GetProperty("DeviceID");
// Definition of Maximum allowable disk utilization percentage
// Change this value to what you want to alarm at. We use 90%.
var nMaxUtilizationPercentage = 90;
// Retrieve the data for the device
var sSql = "SELECT p.nDeviceID, e.sDescription, d.nUsed_Max, d.nSize FROM PivotStatisticalMonitorTypeToDevice p INNER JOIN StatisticalDiskIdentification e ON p.nPivotStatisticalMonitorTypeToDeviceID = e.nPivotStatisticalMonitorTypeToDeviceID INNER JOIN StatisticalDiskCache d ON e.nStatisticalDiskIdentificationID = d.nStatisticalDiskIdentificationID WHERE p.nDeviceID = " + nDeviceID + " AND (d.dPollTime+3) > getdate()";
oRs2 = oDb.Execute(sSql);
if(!oRs2.EOF) {
oRs2.moveFirst();
while ( !oRs2.EOF ) {
var sDescription = oRs2("sDescription");
var nUsed_Max = oRs2("nUsed_Max");
var nSize = oRs2("nSize");
if ( nSize > 0 ) {
var nDiskUsedPercentage = Math.round(nUsed_Max/nSize * 100);
if ( nDiskUsedPercentage >= nMaxUtilizationPercentage ) {
bAlarm = true;
oDisplay += "Disk " + sDescription;
oDisplay += " is ";
oDisplay += nDiskUsedPercentage;
oDisplay += " % full | ";
}
}
oRs2.moveNext();
}
}
else {
bAlarm = true;
oDisplay = "The Diskdata is to old!";
}
//// Here is the end of the checks now put the message into the attribute
//// You have to check if vars like "nDeviceID" or errorholders (here oDisplay) have other names
// Check if the Attribute DSTATUS is Allready provided
var sSqlattr = "SELECT sValue FROM DeviceAttribute WHERE nDeviceID = " + nDeviceID + " AND sName LIKE 'DSTATUS'";
var rsattr = oDb.Execute(sSqlattr);
if (bAlarm == false) {
oDisplay="Drives OK";
}
if(!rsattr.EOF) {
// Attribute is available
} else {
// Create Attribute
var sSqlattr2 = "INSERT INTO DeviceAttribute (nDeviceID,sName,sValue) VALUES('"+nDeviceID+"','DSTATUS','"+oDisplay+"')";
oDb.Execute(sSqlattr2);
}
var sSqlattr3 = "UPDATE DeviceAttribute SET sValue = '"+oDisplay+"' WHERE nDeviceID = " + nDeviceID + " AND sName LIKE 'DSTATUS'";
oDb.Execute(sSqlattr3);
rsattr.Close();
//// End of attribute setup now set Context result
if (bAlarm) {
Context.SetResult( 1, oDisplay);
} else {
Context.SetResult(0, "Drives Ok");
}
}
oDb.Close();
So every time your check runs, the Attribute DSTATUS is updated. Now you have to add code to your emailcontent go here:
Configure / Action Library / ACTION NAME / Edit / Tab: Mail Content
Add this code at the bottom:
Additional information (from script monitor):
%Device.Attribute.USTATUS
%Device.Attribute.DSTATUS
You see I have not only set up DSTATUS Information, also USTATUS. Inside my other script where I monitor URL Checks this snippet is used too, but with other Attributename. So both script can work on the same Device. This avoids that the attribute is overwritten by another script. So change the Letter in the beginning of STATUS to a letter representing your script, to better keep in mind (do that in all 3 sql strings now containing DSTATUS). If your scripts work with attributes be sure not to use prefixes that are used by your scripts.
Hope that helps, ask if you have any further questions
Jan |
| | | | Forum Member
       
Group: Forum Members Last Login: 6/20/2008 5:33:31 AM Posts: 38, Visits: 160 |
| Hey
it finally works !!!!
I had to change things in the script ( in mine ) and i understand well how it works thanks to you.
It's really cool, you're my hero  
I'll try to adapt this on toher script , and great thanks man! |
| | | | Forum Guru
       
Group: Forum Members Last Login: 9/18/2008 7:15:13 AM Posts: 71, Visits: 177 |
| Hey you're welcome |
| | | | Forum Member
       
Group: Forum Members Last Login: 6/20/2008 5:33:31 AM Posts: 38, Visits: 160 |
| Hi stanley 
I have another question for you it's about DSTATUS and USTATUS. I found this idea interesting cause you've got all information into the same mail, but i can't use it.
I use the script on the memory on DSTATUS, and i use the same script ( it's a little bit different in SQL but no way ) and i just replace the DSTATUS by USTATUS.
But when i try to use USTATUS in mail, it return me that the attribute doesn't exist, and i don't know why. I try to change some things but now way. The DSTATUS still work but the USTATUS not.
Thanks 
Edit : Hi It finally works Thanks !!! |
| | | | Forum Guru
       
Group: Forum Members Last Login: 9/18/2008 7:15:13 AM Posts: 71, Visits: 177 |
| Do you change the Keyword DSTATUS in all three SQL strings to USTATUS? Firsttime it checks if the attribute is allready provided - if not the second SQL creates this attribute. After that the third SQL populate the attribute with the errormessage. Or am I missunderstood you? If you have just the DSTATUS Script attached to your device there will be shurely no USTATUS Information in mail. I've got the same on my devices. Some uses that some the other script so often there is information in one of the placeholders in the mail, the other one generates an error like "The '%Device.Attribute.DSTATUS' attribute does not exist"
Helpfull?
Jan |
| | | | Forum Member
       
Group: Forum Members Last Login: 6/20/2008 5:33:31 AM Posts: 38, Visits: 160 |
| yes, thanks you.
More than helpfull!!!!!!!! and i can create complete mail no and that's really interressant |
| | | | Forum Guru
       
Group: Forum Members Last Login: 9/18/2008 7:15:13 AM Posts: 71, |
| |
|