Notification
- Class to handle a notification and its events.
use Notification;
use SysSchema;
# create instance
my $n=Notification->new();
event","timestamp","type","about","from","message"
# define event hash
my %e;
$e{event}=$Notification::MESSAGE;
$e{type}=$SysSchema::NTYP{"user.create"}{id};
$e{about}=1234;
$e{from}=$SysSchema::FROM_REST;
$e{message}="Hello\nA user account has been created for you. Here are the details etc...\n";
# add event
if (!$n->add(\%e)) {
print "ERROR: ".$n->error()."\n";
}
# get a named event (file name without folder must be provided)
my $h=$n->get("012345678901234567890123456789CB_1234567890.12345_message");
# update known events
$n->update();
# reset getnext event
$n->resetNext();
# get next event
# that we know of (see update())
my $h=$n->getNext();
# delete/remove all events
$n->delete();
# get notification id
my $id=$n->id();
# get absolute folder path of
# notification
my $folder=$n->folder();
# get last error
print $n->error();
A class to handle the AURORA-systems notifications. The class specifically handles the notification-folder and its events.
The class enables events to be added and to be read, as well as iterated over in correct and timestamped-order. It also can remove all events (eg. prior to a cleanup/removal).
Please see the AURORA notification-service documentation for more information about events and the structure of the service.
Instantiate class.
The method takes two inputs: id and folder. Id specifies the notification ID to use. If none is specified it creates a random one for you. Folder specifies the absolute path to the AURORA main/root notification-folder. If not specified it will default to "/local/app/aurora/notification".
Returns a class object.
Adds an event to the notification.
Input is a HASH-reference with the necessary key->value definitions for the various event-types. The input is mandatory.
Valid event types are:
$Notification::MESSAGE - message-event (typically starts a notification).
$Notification::NOTICE - notice-event (generated each time a notice is sent with a notice-class)
$Notification::ESCALATION - escalation-event (generated when timeout reaching people has been reached and no confirmation from any user(s))
$Notification::ACK - ack-event (generated when someone confirms/acknowledge a notice-event)
$Notification::FIN - fin-event (marks that one is finished parsing this Notification)
The following are the required keys for the various event types:
MESSAGE ("event","timestamp","type","about","from","message")
NOTICE ("event","timestamp","class","rid","whom","votes","status","message")
ESCALATION ("event","timestamp","level","who")
ACK ("event","timestamp","rid")
FIN ("event","timestamp");
All events share the keys "event" and "timestamp", which defines the type of event and timedate respectively of the event.
The key "event" is to be filled with one of the constant mentioned above ($Notification::MESSAGE, $Notification::ACK etc.). "timestamp" can be omitted and then it will be filled with current time. If specified it should use HiRes-time.
Please see AURORA Notification-specification for more information on the various key-values.
Returns 0 upon failure or 1 upon success. Please check the error()-method for more information upon failure.
Get an event of the notification.
Mandatory input is the name of the event-file. The event-file name is in the following format:
NOTID_TIMESTAMP_EVENTTYPE
NOTID is the notification id of 32 random characters (a-zA-Z0-9). Timestamp is the HiRes-timestamp of when the event happened and EVENTTYPE is the type of event (eg. "message"). The EVENTTYPE is always specified in lowercase.
Returns a HASH-reference with the event data upon success, undef upon failure. Please check the error()-method for more information upon failure.
Resets the next pos pointer for reading out notification events.
No input accepted. Always returns 1.
Gets the next event in the event list of the notification.
No input is accepted.
Returns the HASH-reference to the event data upon success, undef upon failure. Please check the error()-method for more information upon failure.
Deletes all events of the notification.
No input is accepted.
It attempts to unlink all event-files in the Notification-folder of the specific notification. If there are other files there than event-files, it does not touch these.
Always returns 1.
Returns the notification ID of the instance.
No input is accepted.
Returns the notification ID.
Returns the absolute folder path of the notification root-folder.
No input is accepted.
Returns the absolute folder path of the notification root-folder.
Returns the last error that has happened (if any).
No input is accepted.