File: hpov.alert

package info (click to toggle)
mon-contrib 1.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 896 kB
  • sloc: perl: 5,510; sh: 391; python: 118; makefile: 72
file content (143 lines) | stat: -rwxr-xr-x 4,477 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/perl
#
# hpov.alert - generate event in HP OpenView
#
# Arguments:
#       -c:  severity of condition (Critical, Major, Minor, etc.)
#            Default is "Major".
#       -C:  Category of event.  Default is "Error Alarms".
#       -m:  address of HP OpenView manager.  Default is "localhost".
#       -o:  Event OID.  REQUIRED.  If event OID does not start with
#            a ".", default prefix is .1.3.6.1.4.1.11.2.17.1.0 for
#            event OID and info is passed in the MIB branch
#            .1.3.6.1.4.1.11.2.17.2.x.0
#
# Sends alert with hostgroup name as address of snmp agent that originated the
# alarm.  This means that hostgroups that use this alert type must be valid
# IPs or domain names.
#
# Upalerts are sent with severity "Normal".  Should be used with rearm event
# OIDs in HP Open View.
#
# See the section "Configuration" below to change defaults.
#
# Scott Prater, sprater@servicom2000.com, 2001.  Based on file.alert by
# Jim Trocki, trockij@transmeta.com
#
# $Id: hpov.alert,v 1.1.1.1 2005/02/18 17:52:13 trockij Exp $
#
#    Copyright (C) 1998, Jim Trocki
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
#

$RCSID='$Id: hpov.alert,v 1.1.1.1 2005/02/18 17:52:13 trockij Exp $' ;
use strict;
use vars qw($opt_d $opt_S $opt_s $opt_g $opt_h $opt_t $opt_l $opt_c $opt_C
$opt_m $opt_o $opt_u $opt_T $opt_O);
use Getopt::Std;

getopts ("d:S:s:g:h:t:l:c:C:m:o:uOT");

#---------------------------------------------------------#
# Configuration (edit as needed to suit your environment) #
#---------------------------------------------------------#

if (!$opt_o)
{
    die "Could not generate HPOV event:  no Event OID\n";
}

my $OV_BIN = "/opt/OV/bin";     # Path to HP OpenView bin directory
my $OV_EVENT = "ovevent";       # Name of HP OpenView program to generate alarms

my $SEVERITY = $opt_c || "Major";
my $CATEGORY = $opt_C || "Error Alarms";
my $MANAGER = $opt_m || "localhost";
my $OID = $opt_o;
my $DEFAULT_MIB_BRANCH = ".1.3.6.1.4.1.11.2.17";
my $DEFAULT_MIB_SUFFIX = ".0";
my $UPALERT_SEVERITY = "Normal";

#---------------------------------------------------------#
# End Configuration                                       #
#---------------------------------------------------------#

my $counter = 1;
my ($event_oid, $event_oid_branch, $event_oid_suffix);

my $summary=<STDIN>;
chomp $summary;
my $summary = $opt_S if ($opt_S);

if ($OID !~ /^\./)
{
    $event_oid = $DEFAULT_MIB_BRANCH . ".1.0." . $OID;
    $event_oid_branch = $DEFAULT_MIB_BRANCH . ".2";
    $event_oid_suffix = $DEFAULT_MIB_SUFFIX;
}
else
{
    $event_oid = $OID;
    $event_oid_branch = $OID;
    $event_oid_suffix = "";
}

my $ALERT = $ENV{"MON_ALERTTYPE"} || "UNKNOWN ALERT";
my $RETVAL = $ENV{"MON_RETVAL"} || 0;

# If this is an upalert, send rearm event OID to HPOV with proper severity
if ($opt_u)
{
   $SEVERITY = $UPALERT_SEVERITY;
}

my $t = localtime($opt_t);
my ($wday,$mon,$day,$tm) = split (/\s+/, $t);

# MIB tree structure
# First Var:  integer (for return code)
# Second var:  summary line
# Following vars:  detailed output, line by line

my $first_var = "$event_oid_branch.$counter$event_oid_suffix Integer
$RETVAL";
$counter++;
my $second_var = "$event_oid_branch.$counter$event_oid_suffix OctetString
\'$ALERT $opt_g $opt_s $opt_t --$wday $mon $day $tm-- $summary\'";
$counter++;
my $cmd =  "$OV_BIN/$OV_EVENT -s $SEVERITY -c \"$CATEGORY\" -a $opt_g
\"$MANAGER\" $event_oid $first_var $second_var";

#
# The remaining lines contain more detailed information:
# add them to the MIB branch.
#
while (<STDIN>) {
    chomp;
    $cmd .= " $event_oid_branch.$counter$event_oid_suffix OctetString
\'$_\'";
    $counter++;
}


# Send the alarm
my $exit_status = system($cmd);
if ($exit_status != 0)
{
    die ("Cannot send event to HPOV:  !$\n");
}

exit;