...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<add_order job_chain ="sos/notification/ResetNotifications" id ="OP5 MyServiceNameop5 JobScheduler Monitoring Error acknowledgement" title ="OP5 MyServiceNameop5 JobScheduler Monitoring Error acknowledgement"> <params> <param name="service_name" value="MyServiceNameJobScheduler Monitoring Error" /> <param name="system_id" value="OP5op5"/> <param name="operation" value="acknowledge" /> </params> </add_order> |
Example ResetNotifications OP5 add_order perl
...
/add_order> |
Key to the above code:
Element | Attribute | Value | Description | |
---|---|---|---|---|
add_order | XML Command to add the new order to the specified job chain on the JobScheduler. | |||
job_chain | sos/notification/ResetNotifications | Job chain path must correspond with the path of the ResetNotifications job chain installed on the JobScheduler. | ||
id | Order identifier. | |||
title | Order title. | |||
param | 3 following parameters must be set: | |||
name | service_name | JobScheduler Monitoring Error | Relevant service name to set all already occured service errors in JobScheduler Interface Monitor as acknowledged. | |
name | system_id | op5 | System identification. Corresponds with | |
name | operation | acknowledge |
Example ResetNotifications OP5 add_order perl
This example shows the integration of a Perl script into OP5 monitor system that automatically sends the above XML command to the JobScheduler sos/notification/ResetNotifications
job chain.
The "Acknowledgment" on the op5 Monitor side works as follows:
- Contact "acknowledgment" + Event Handler:
- it first of all requires a contact, that receives the Notifications in the same way as the other contacts. However, an event notification for this contact is not received via Mail but an Event Handler, i.e. an XML command will be executed instead of a mail being received. (Please see the next point, "
Notification Command
".)
- it first of all requires a contact, that receives the Notifications in the same way as the other contacts. However, an event notification for this contact is not received via Mail but an Event Handler, i.e. an XML command will be executed instead of a mail being received. (Please see the next point, "
- The "svc_notify_ack_handle"
Notification Command
:- this command will always be executed for the services that are specified for the contact. This command is executed when the service status changes (for example, by a change from
OK
toCritical
orAcknowledgment
of an Error). - The command executes a
check_acknowledge.pl
script.
- this command will always be executed for the services that are specified for the contact. This command is executed when the service status changes (for example, by a change from
- The
check_acknowledge.pl
Script (see the example below): this script is executed by the command and first of all checks whether the command is a response to anAcknowledgment
: - If the command is not a response to an
Acknowledgment
: then nothing happens - If the command is a response to an
Acknowledgment
: then the script causes the JobScheduler to be contacted and sent am XML query, that instructs the JobScheduler to start a specific job chain (thesos/notification/ResetNotifications
chain)
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/usr/bin/perl -w use strict; use Net::HTTP; use Getopt::Long; use vars qw($opt_H $opt_f $opt_s $opt_p $opt_t $opt_h); use vars qw(%ERRORS &support); my $host; my $type; my $service; my $port; my $timeout = 30; our %ERROR; %ERRORS = ( 'OK' => 0, 'CRITICAL' => 2, 'ERROR' => 2, 'UNKNOWN' => 9, 'WARNING' => 1, ); sub print_help (); sub print_usage (); Getopt::Long::Configure('bundling'); GetOptions ("h" => \$opt_h, "help" => \$opt_h, "H=s" => \$opt_H, "hostname=s" => \$opt_H, "f=s" => \$opt_f, "s=s" => \$opt_s, "service=s" => \$opt_s, "t=i" => \$opt_t, "timeout=i" => \$opt_t, "p=i" => \$opt_p, "port=i" => \$opt_p); if ($opt_h) {print_help(); exit 0;} if ($opt_H ) { if ( $opt_H =~ /([-.A-Za-z0-9]+)/ ) { $host = $opt_H; } ($host) || print("Invalid host: $opt_H\n"); } else { print("Host name/address not specified\n"); } if ($opt_p ) { if ($opt_p =~ /([0-9]+)/) { $port = $1 if ($opt_p =~ /([0-9]+)/); } ($port < 0 || $port > 65535) && print("Invalid Port: $opt_p\n"); } else { print("Port not specified\n"); } if ($opt_t) { $timeout = $opt_t; } if( !$host || !$port ) { print_usage(); exit 1; } $opt_s=~ s/ /%20/g; print("service name:$opt_s\n"); # $job_scheduler_request output example. # MyServiceName "JobScheduler Monitoring Error" is the example of the service name $opt_s. #<add_order job_chain ="sos/notification/ResetNotifications" # id ="OP5 MyServiceNameop5 JobScheduler Monitoring Error acknowledgement" # title ="OP5 MyServiceNameop5 JobScheduler Monitoring Error acknowledgement"> # <params> # <param name="service_name" value="MyServiceNameJobScheduler Monitoring Error" /> # <param name="system_id" value="OP5op5"/> # <param name="operation" value="acknowledge" /> # </params> #</add_order> my $job_scheduler_request = "%3Cadd_order%20job_chain=%22sos/notification/ResetNotifications%22%20id=%22OP5%20%22op5%20".$opt _s."%20acknowledgement%22%20title=%22OP5%20%22op5%20".$opt_s."%20acknowledgement%22%3E%3Cparams%3E%3Cparam%20name=%22syst em_id%22%20value=%22op5%22/%3E%3Cparam%20name=%22service_name%22%20value=%22".$opt_s."%22/%3E%3Cparam%20name=%22 operation%22%20value=%22acknowledge%22/%3E%3C/params%3E%3C/add_order%3E"; if($opt_f=~m/ACKNOWLEDGEMENT/){ my $jobscheduler_answer_xml = get_answer($job_scheduler_request); my $jobscheduler_state_element = get_state_elem($jobscheduler_answer_xml); my $jobscheduler_state = get_attribute_value("state",$jobscheduler_state_element); _report('OK', "OK: Service Name is " . $opt_s . " and notification type is ". $opt_f ." and JS request is ". $job_scheduler_request. "\n"); } else{print("Sorry, but this is not an acknowledgement\n");} sub get_attribute_value { my ($attr_name, $elem_xml) = @_; $elem_xml =~ s/.*$attr_name\s*=\s*\"(.*?)\".*/$1/s; return $elem_xml; } sub get_state_elem { my $xml = shift; $xml =~ s/.*<spooler.*?>\s*<answer.*?>\s*(<state.*?>).*/$1/s; return $xml; } sub get_answer { my $request = shift; my $socket = Net::HTTP->new(Host => $host, PeerPort => $port, Timeout => $timeout); my $xmlAnswer = ""; if ($socket) { $socket->write_request(GET => $request); my($code, $mess, %h) = $socket->read_response_headers; if ($code == 200) { while (1) { my $buf; my $n = $socket->read_entity_body($buf, 1024); last unless $n; $xmlAnswer .= $buf; } } else { _report('ERROR',"Connection to JobScheduler " . $host . ":" . $port . " failed: (" . $code . ") " . $mess . "\n"); } } else { _report('CRITICAL',"Connection to JobScheduler " . $host . ":" . $port . " failed: " . $@ . "\n"); } return $xmlAnswer; } sub print_help () { print $0. "\n"; print "Copyright (c) 2012 SOS GmbH, info\@sos-berlin.com This script tries to connect to given Job Scheduler "; print_usage(); print " -H, --hostname=HOST Name or IP address of host to check -p, --port=INTEGER Port at host to check -t, --timeout=INTEGER Timeout for HTTP connetion -h, --help This help "; } sub print_usage () { print "Usage: $0 -H <host> -p <port> [-t <timeout>]\n"; } sub _report { print $_[1]; if (defined($ERRORS{$_[0]})) { exit $ERRORS{$_[0]}; } else { exit 0; } } |
...
JobScheduler - Job Chains customization
...