Start a Conversation

This post is more than 5 years old

Solved!

Go to Solution

1087

November 20th, 2008 00:00

Perl API - create notification

Hello all.

I have create notification from script.

a question is:

I should to declare events in Model or configuration files ???

My code is

# -- Get instances from class ImapServer
foreach $inst (sort $session->getInstances($class)) {
print $class . "::" . $inst . "\n";

# -- Create the object for each instance
$obj = $session->object($inst);

# -- continue with next element if object is no defined
next if ($obj->isNull());


# to notify an event:
$session->forceNotify($obj,
"BLA", 0, 1);

This is fragment from log file
[20-Nov-2008 03:03:01 PM NOVT] Perl-Client-14843-1(126):
forceNotify(ImapServer::SRVO-ImapServer::BLA,NOTIFY)

But, no see events in Console ....


What do i do for ?

November 21st, 2008 07:00

Hi Hemul,

there is two different ways to send "alarms" to SAM:

(1) using "events" coming from domain manager, which then turn to ICS_Notification instances,

(2) using ICS_Notification instances directly, from OI (preferred) or SAM.

There is no "one solution", it depends what you want to achieve. If you want to add alarms "dynamically" without being attached to a model (compile, load, restart domain manager, ...), then ICS_Notification is a better solution. If you need correlation, attributes, some processing, Dynamic Model is a better solution.

Lets say you want to do (1), then, in my opinion, you should still use an attribute to raise event, it is a better way to do so. So, you will have something like:

stored attribute boolean A_Unresponsive
"Bla"
= FALSE;

event Unresponsive
"This is the eventText"
= A_Unresponsive;

export Unresponsive;

and when you want to raise "Unresponsive", you just have to set "A_Unresponsive" to "TRUE".
In this case, don't forget to build a new / change an existing DXA in order to make SAM subscribes to this event / problem / ....


Lets say you want to do (2), then, you don't have to use sm_ems, you can use any API (PERL, Java, C). Simply use the right classes / methods to do so. It's not really complex but it is definitively not simple enought to be summarize here. Look at the ICS_NotificationFactory class.

HTH,

--Fred

Frederic Meunier
Solutions Watch4Net Inc
APG (performance management) & Smarts InCharge (fault management) integration
http://www.watch4net.com

November 20th, 2008 06:00

Hi Hemul,

some information is missing is:
- are you using Dynamic Model (event in IP) or do you want to send notifications directly to OI/SAM without using/creating a new model ?
- DynamicModel: yes, you have to create a new event, export it, and subscribe to it from SAM (using the DXA),
- SAM/OI notifications: you can send any alarms directly to OI/SAM, as a notification, but you don't use the same API methods for that.

--Fred

Frederic Meunier
Solutions Watch4Net Inc
APG (performance management) & Smarts InCharge (fault management) integration
http://www.watch4net.com

2 Intern

 • 

138 Posts

November 20th, 2008 20:00

HI FredMeunier!

I use Model for this issue, this is Imap and Pop3 service cheker, NOT ACM - in script i connect to IMAP server and read mails from MailBox.

In Dynamc Model i have create only interface ImapServer with special attributes attributes (username, ipaddress, etc ....)

Then from Perl script i get Instances from this Class and check each device.
Now, if i declare events directly in model i should to declare expressions for event ad more ..
I wan to notify SAM directly , because i want to receive for example:
Event: ImapCheckFailed
EventText: here to insert the reason, for example "login si failed or connection reset by peer, etc ...."

How can i realize this ?


--but you don't use the same API methods for that.
What is different method ?
I hope you did not mean sm_ems command ?

2 Intern

 • 

138 Posts

November 23rd, 2008 22:00

Hello Fred.

Thank you for operative, high quality and full response.

First way is most elegant way to do this, but i have no idea how to create different event text for each event, for example event: ServiceUnresponsive may contain some event text
1) Connection failed
2) Authentication failed etc ...
really i don't know how many and which errors (eventText) i have, because can't create different event for each error.
A lot of thanks.

2 Intern

 • 

138 Posts

December 10th, 2008 20:00

Hello.

Really, I was realized my issue "Create notification via Perl API in SAM"

This is code example:

// code
// Create session
# -- Create session
$session = InCharge::session->new(
broker=>"127.0.0.1",
domain=>$domain,
username=>"admin",
password=>"changeme",
traceServer => 1
);
# create new event
sub NotifNew {
$icsNotificationFactory = $session->object($session->getInstances($notifFactoryClass));

$eventObj = $icsNotificationFactory->makeNotification($class, $obj->{DisplayName}, $eventName);

$eventObj = $session->object($eventObj);

# -- set event variables
$eventObj->{EventText} = $xErr;
$eventObj->{Severity} = $minor;
$eventObj->{Category} = "Availability";
$eventObj->{InMaintenance} = 1;
$eventObj->{ClearOnAcknowledge} = 1;
$eventObj->{EventType} = "DURABLE";

@arr5 = ($user, $domain, "Event has created by Imap Poller", 0, 7200);
$session->invoke($eventObj, "notify", @arr5);
$eventObj->changed(time);
}
# clear event if defined
sub ClearNotif {

# -- create Factory object
$icsNotificationFactory = $session->object($session->getInstances($notifFactoryClass));

if ($eventObj = $icsNotificationFactory->findNotification($class, $obj->{DisplayName}, $eventName) ) {

# -- event is defined
$eventObj = $session->object($eventObj);
# -- if event is active, close it
if ( ($eventObj->{Active} == 1) or ($eventObj->{EventState} eq "ACTIVE") ) {

@arrClear = ($user, $domain, "Event has closed by POP3 Poller, POP3 service is return to normal state.");
$session->invoke($eventObj, "clear", @arrClear);
$eventObj->changed(time);
}
}
}
No Events found!

Top