| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# Copyright (c) 2008 Klaas Freitag <freitag@suse.de>, Novell Inc. |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 2 as |
| 7 |
# published by the Free Software Foundation. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program (see the file COPYING); if not, write to the |
| 16 |
# Free Software Foundation, Inc., |
| 17 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 18 |
# |
| 19 |
################################################################ |
| 20 |
# Contributors: |
| 21 |
# Klaas Freitag <freitag@suse.de> |
| 22 |
# |
| 23 |
# This is a commandline script to notify hermes which generates Messages |
| 24 |
# from it. |
| 25 |
|
| 26 |
use strict; |
| 27 |
use Getopt::Std; |
| 28 |
|
| 29 |
use Hermes::Message; |
| 30 |
use Hermes::Log; |
| 31 |
|
| 32 |
use vars qw ( $opt_o $opt_h $opt_r ); |
| 33 |
|
| 34 |
sub help |
| 35 |
{ |
| 36 |
print<<END |
| 37 |
|
| 38 |
NAME |
| 39 |
notifyHermes.pl - schedule a notification to the hermes system. |
| 40 |
|
| 41 |
SYNOPSIS |
| 42 |
|
| 43 |
notifyHermes.pl [option...] type |
| 44 |
|
| 45 |
DESCRIPTION |
| 46 |
|
| 47 |
Calling notifyHermes schedules a notification into the hermes system. |
| 48 |
All people subscribed to the notification type will get a message |
| 49 |
according to their setting of the delay and delivery type. |
| 50 |
|
| 51 |
Options: |
| 52 |
-o string: The parameter that gets processed to the message template |
| 53 |
later on. Multiple parameter can be added comma separated. |
| 54 |
-r: Create raw notification, ie. in notification inbox tables |
| 55 |
-h: This help |
| 56 |
|
| 57 |
EXAMPLE: |
| 58 |
|
| 59 |
Place a notification: |
| 60 |
|
| 61 |
notifyHermes -o 'bla=foo, bar=baz' CheckHermes |
| 62 |
|
| 63 |
fires the notification type CheckHermes with the parameters bla = foo |
| 64 |
and bar = baz. |
| 65 |
|
| 66 |
END |
| 67 |
; |
| 68 |
|
| 69 |
exit; |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
# ====================================================================== |
| 74 |
|
| 75 |
getopts( 'ro:h' ); |
| 76 |
|
| 77 |
my ($type) = @ARGV; |
| 78 |
|
| 79 |
help() if( $opt_h ); |
| 80 |
setLogFileName('notifyHermes'); |
| 81 |
|
| 82 |
my %params; |
| 83 |
|
| 84 |
if( $opt_o ) { |
| 85 |
my @opts = split( /\s*,\s*/, $opt_o ); |
| 86 |
foreach my $opt ( @opts ) { |
| 87 |
my ($key, $val) = split( /\s*=\s*/, $opt ); |
| 88 |
$params{$key} = $val; |
| 89 |
print "Parameter: $key = $val\n"; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
die "No notification type specified" unless( defined $type ); |
| 94 |
|
| 95 |
my $id = notificationToInbox( $type, \%params ); |
| 96 |
|
| 97 |
if( $id ) { |
| 98 |
print "Message created: $id\n"; |
| 99 |
} else { |
| 100 |
print "No message created\n"; |
| 101 |
} |
| 102 |
|
| 103 |
# END |