Start a Conversation

Unsolved

This post is more than 5 years old

779

April 15th, 2008 10:00

epoch Time() - First Notified - Last notified

I have an escalation policy that calls a .cmd file, and that .cmd file then calls an .asl script. When I print the SM_OBJ_FirstNotified at, I see that those time stamps are passed as epoch times. I want them to print in Date and Time format instead of epoch format. The asl.pdf reference guide shows how to use time() function for stamping the message with an exact system time as of that moment, but it does not show how to feed the %SM_OBJ_FirstNotifiedAt% (which I pass to the .asl script via sm_adapter and the Operating system environment.) to the time() function so that it converts the epoch times for FirstNotifiedAt, LastNotifiedAt, and LastChangedAT into a human readable date and time like 15-Apr-2008 14:45:00

What it prints is just the epoch number like 9123199849 (this is not a real epoch time, but it might as well be a random number for all it's usefullness in an email alert.)

-DLastNotifiedAt="1208187564" -DFirstNotifiedAt="1208187564" -DInstanceName="10.30.103.32" -DLastClearedAt="0" -DLastChangedAt="1208188754"

Here is the .cmd that is called by the escalation policy.

sm_adapter -M sm_actions -DsenderName="SMARTS@company.com" -DreceiverName="david_redwine@company.com" -DeventState="%SM_OBJ_EventState%" -DclassName="%SM_OBJ_ClassName%" -DuserDefined1="%SM_OBJ_UserDefined1%" -DeventText="%SM_OBJ_EventText%" -DeventDisplayName="%SM_OBJ_EventDisplayName%" -DLastNotifiedAt="%SM_OBJ_LastNotifiedAt%" -DFirstNotifiedAt="%SM_OBJ_FirstNotifiedAt%" -DInstanceName="%SM_OBJ_InstanceName%" -DLastClearedAt="%SM_OBJ_LastClearedAt%" -DLastChangedAt="%SM_OBJ_LastChangedAt%" -DdisplayName="%SM_OBJ_DisplayName%" -DelementName="%SM_OBJ_ElementName%" -Dname="%SM_OBJ_Name%" -DNotifierName="%SM_OBJ_NotifierName%" %SM_HOME%/local/script/notifier/sendEMail_DR1.asl


and the .asl I am trying to get to work is

systemObj = object("SM_System", "SM-System");
default senderName = "SMARTS@company.com";
default receiverName = "internet@company.com";
default fromAddress = "EMC - SMARTS";
default className = "Router";
default userDefined1 = "Router1";
default eventText = "This is the content of the event";
default eventDisplayName = "DOWN";
default lastNotifiedAt = "";
default lastChangedAt = "";
default displayName = "Fallback to Default";
default elementName = "Fallback to Default";
default name = "Fallback to Default";
default firstNotifiedAt = "";
default debug = TRUE;

START {
.. eol
} do {

/*
* className = systemObj->getenv("SM_OBJ_ClassName");
* userDefined1 = systemObj->getenv("SM_OBJ_UserDefined1");
* eventText = systemObj->getenv("SM_OBJ_EventText");
* eventDisplayName = systemObj->getenv("SM_OBJ_EventDisplayName");
* firstNotifiedAt = systemObj->getenv("SM_OBJ_FirstNotifiedAt");
* lastNotifiedAt = systemObj->getenv("SM_OBJ_LastNotifiedAt");
* lastChangedAt = systemObj->getenv("SM_OBJ_LastChangedAt");
* displayName = systemObj->getenv("SM_OBJ_DisplayName");
* elementName = systemObj->getenv("SM_OBJ_ElementName");
* name = systemObj->getenv("SM_OBJ_Name");
*/

if (debug) {
print("className=".className." System name=".userDefined1);
print("eventDisplayName=".eventDisplayName);
print("eventText=".eventText);
print("firstNotifiedAt=".firstNotifiedAt);
print("lastNotifiedAt=".lastNotifiedAt);
print("lastChangedAt=".lastChangedAt);
print("displayName=".displayName);
print("elementName=".elementName);
print("name=".name);
}
epochfirstNotifiedAt = string(time().firstNotifiedAt);
print(epochfirstNotifiedAt);

epochlastNotifiedAt = string(time().lastNotifiedAt);
print(epochlastNotifiedAt);

epochlastChangedAt = string(time().lastChangedAt);
print(epochlastChangedAt);

subjectText = " SMARTS-- " .className . " " . userDefined1 . " " .eventDisplayName ;
bodyText = "Event Text: " . eventText . "\n\n".
"First Notified: " . epochfirstNotifiedAt . "\n\n".
"Last Notified: " . epochlastNotifiedAt . "\n\n".
"Last Changed : " . epochlastChangedAt . "\n\n".
"Display Name: " . displayName . "\n\n".
"Element Name: " . elementName ;

mailObj = create("ACT_Mail", "sendEmail");
mailObj->SMTPServer = "smtp-out.us.company.com";
mailObj->sendmail(senderName, receiverName, subjectText, bodyText);
}

What the .asl script above does is just print the system time 3 times. it doesn't convert the epoch times which I have passed to it. The secret is bound to be in how the time() function is used, but the .asl reference guide "cuts off" the section on how to use the time() function to convert an epoch time which you feed into it via a variable.

April 18th, 2008 06:00

Hi,

not quite sure that I understand exactly what you want to do, but if you want to print a date in string format from a epoch format, just do that:

this_date_in_epoch = 1208187564;

print(time(this_date_in_epoch));

HTH,

--Fred

Frederic Meunier
Solutions Watch4Net Inc
APG & Smarts InCharge integration
http://www.watch4net.com

10 Posts

May 14th, 2008 08:00

OK, I figured it out (actually about 3 weeks ago, but though I would go ahead and post the info for others who might want to send firstnotifedat, lastnotifiedat timestamps in their smtp oriented escalation policy or policies.

The escalation policy calls SendEMail_dredwine.cmd which contains the following

echo %SM_OBJ_FirstNotifiedAt%
echo %SM_OBJ_FirstNotifiedAt%
echo %SM_OBJ_LastNotifiedAt%
echo %SM_OBJ_LastChangedAt%
echo %SM_OBJ_DisplayName%
echo %SM_OBJ_ElementName%
echo %SM_OBJ_Name%

rem set
sm_adapter -M sm_actions -DsenderName="SMARTS@dell.com" -DreceiverName="david_redwine@dell.com" -DeventState="%SM_OBJ_EventState%" -DclassName="%SM_OBJ_ClassName%" -DuserDefined1="%SM_OBJ_UserDefined1%" -DeventText="%SM_OBJ_EventText%" -DeventDisplayName="%SM_OBJ_EventDisplayName%" -DLastNotifiedAt="%SM_OBJ_LastNotifiedAt%" -DFirstNotifiedAt="%SM_OBJ_FirstNotifiedAt%" -DInstanceName="%SM_OBJ_InstanceName%" -DLastClearedAt="%SM_OBJ_LastClearedAt%" -DLastChangedAt="%SM_OBJ_LastChangedAt%" -DdisplayName="%SM_OBJ_DisplayName%" -DelementName="%SM_OBJ_ElementName%" -Dname="%SM_OBJ_Name%" -DNotifierName="%SM_OBJ_NotifierName%" %SM_HOME%/local/script/notifier/sendEMail_DR4.asl

As you can see the SendEMail_dredwine.com calls sendEMail_DR4.asl which contains the following:

systemObj = object("SM_System", "SM-System");
default senderName = "SMARTS@dell.com";
default receiverName = "internet@dell.com";
default fromAddress = "EMC - SMARTS";
default className = "Router";
default userDefined1 = "Router1";
default eventText = "This is the content of the event";
default eventDisplayName = "DOWN";
default displayName = "Fallback to Default";
default elementName = "Fallback to Default";
default name = "Fallback to Default";
default lastNotifiedAt = "";
default lastChangedAt = "";
default firstNotifiedAt = "";
default debug = TRUE;

START {
..eol
}

do {


className = systemObj->getenv("SM_OBJ_ClassName");
userDefined1 = systemObj->getenv("SM_OBJ_UserDefined1");
eventText = systemObj->getenv("SM_OBJ_EventText");
eventDisplayName = systemObj->getenv("SM_OBJ_EventDisplayName");
firstNotifiedAt = systemObj->getenv("SM_OBJ_FirstNotifiedAt");
lastNotifiedAt = systemObj->getenv("SM_OBJ_LastNotifiedAt");
lastChangedAt = systemObj->getenv("SM_OBJ_LastChangedAt");
displayName = systemObj->getenv("SM_OBJ_DisplayName");
elementName = systemObj->getenv("SM_OBJ_ElementName");
name = systemObj->getenv("SM_OBJ_Name");


if (debug) {
print("className=".className." System name=".userDefined1);
print("eventDisplayName=".eventDisplayName);
print("eventText=".eventText);
print("firstNotifiedAt=".firstNotifiedAt);
print("lastNotifiedAt=".lastNotifiedAt);
print("lastChangedAt=".lastChangedAt);
print("displayName=".displayName);
print("elementName=".elementName);
print("name=".name);
}

epochfirstNotifiedAt = time(firstNotifiedAt);
epochlastNotifiedAt = time(lastNotifiedAt);
epochlastChangedAt = time(lastChangedAt);

subjectText = " SMARTS-- " .className . " " . userDefined1 . " " .eventDisplayName ;
bodyText = "Event Text: " . eventText . "\n\n".
"First Notified: " . epochfirstNotifiedAt . "\n\n".
"Last Notified: " . epochlastNotifiedAt . "\n\n".
"Last Changed : " . epochlastChangedAt . "\n\n".
"Display Name: " . displayName . "\n\n".
"Element Name: " . elementName ;

mailObj = create("ACT_Mail", "sendEmail");
mailObj->SMTPServer = "smtp-out.us.dell.com";
mailObj->sendmail(senderName, receiverName, subjectText, bodyText);
}


and finally this is what the output will look like when you receive the smtp message in your inbox.

-----Original Message-----
From: SMARTS@dell.com [mailto:SMARTS@dell.com]
Sent: Friday, April 18, 2008 5:18 PM
To: Redwine, David - Dell Team
Subject: SMARTS-- PowerSupply_Fault_CiscoStack emf3corpdist01.lim.emea.dell.com StateNotNormal

Event Text: Indicates that the state of the power supply for this system is not NORMAL or SHUTDOWN.

First Notified: 13-Apr-2008 7:01:55 PM Central Daylight Time

Last Notified: 17-Apr-2008 5:55:00 PM Central Daylight Time

Last Changed : 17-Apr-2008 8:00:39 PM Central Daylight Time

Display Name: PowerSupply_Fault_CiscoStack StateNotNormal 100%: PWR-10.64.254.62/2 []

Element Name: 10.64.254.62

-end of alert-
No Events found!

Top