VBTK/DBI/OraLogins.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran n/a Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 72 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
addVBObj
2.0
BEGIN
2.0
CRAP 2.0
1 #############################################################################
2 #
3 # NOTE: This file under revision control using RCS
4 # Any changes made without RCS will be lost
5 #
6 # $Source: /usr/local/cvsroot/vbtk/VBTK/DBI/OraLogins.pm,v $
7 # $Revision: 1.8 $
8 # $Date: 2002/03/04 20:53:07 $
9 # $Author: bhenry $
10 # $Locker: $
11 # $State: Exp $
12 #
13 # Purpose: An extension of VBTK::DBI for use in monitoring logins
14 # in an oracle database
15 #
16 # Depends on: VBTK::Common, VBTK::DBI
17 #
18 # Copyright (C) 1996 - 2002 Brent Henry
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of version 2 of the GNU General Public
22 # License as published by the Free Software Foundation available at:
23 # http://www.gnu.org/copyleft/gpl.html
24 #
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
29 #
30 #############################################################################
31 #
32 #
33 # REVISION HISTORY:
34 #
35 # $Log: OraLogins.pm,v $
36 # Revision 1.8 2002/03/04 20:53:07 bhenry
37 # *** empty log message ***
38 #
39 # Revision 1.7 2002/03/04 16:49:10 bhenry
40 # Changed requirement back to perl 5.6.0
41 #
42 # Revision 1.6 2002/03/02 00:53:55 bhenry
43 # Documentation updates
44 #
45 # Revision 1.5 2002/02/13 07:36:27 bhenry
46 # Disabled RrdLogRecovery and removed use of @log
47 #
48 # Revision 1.4 2002/01/28 19:35:14 bhenry
49 # Bug Fixes
50 #
51 # Revision 1.3 2002/01/25 07:13:31 bhenry
52 # Changed to inherit from VBTK::DBI
53 #
54 # Revision 1.2 2002/01/21 17:07:47 bhenry
55 # Disabled 'uninitialized' warnings
56 #
57 # Revision 1.1.1.1 2002/01/17 18:05:57 bhenry
58 # VBTK Project
59  
60 package VBTK::DBI::OraLogins;
61  
62 use 5.6.0;
63 use strict;
64 use warnings;
65 # I like using undef as a value so I'm turning off the uninitialized warnings
66 no warnings qw(uninitialized);
67  
68 use VBTK::Common;
69 use VBTK::DBI;
70  
71 # Inherit methods from VBTK::DBI;
72 our @ISA=qw(VBTK::DBI);
73  
74 our $VERBOSE = $ENV{VERBOSE};
75  
76 #-------------------------------------------------------------------------------
77 # Function: new
78 # Description: Object constructor. Allocates memory for all class members
79 # Input Parms:
80 # Output Parms: Pointer to class
81 #-------------------------------------------------------------------------------
82 sub new
83 {
84 my $type = shift;
85 my $self = {};
86 bless $self, $type;
87  
88 # Store all passed input name pairs in the object
89 $self->set(@_);
90  
91  
92 my $stdHeader = [
93 'Sid User MemKB Tot IO Delta IO Cmd Blkr Blkd Stat Host HostUser Prog PID Ser# ',
94 '--- --------- ------ --------- -------- --- ---- ---- ------ ----------- -------- -------------------- --------- ------' ];
95  
96 my $stdDetail = [
97 '@>> @<<<<<<<< @>>>>> @>>>>>>>> @>>>>>>> @>> @>>> @>>> @<<<<< @<<<<<<<<<< @<<<<<<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<< @>>>>>',
98 '@data[0..3],$delta[3],@data[4..12]' ];
99  
100 my $sql = q(
101 select sn.sid,
102 sn.username,
103 round(se.value/1024),
104 io.block_gets,
105 sn.command,
106 blkr.blocks,
107 blkd.blocks,
108 sn.status,
109 sn.machine,
110 sn.osuser,
111 sn.program,
112 sn.process,
113 sn.serial#
114 from v$session sn,
115 v$sesstat se,
116 v$statname n,
117 v$sess_io io,
118 (select blocker.session_id sid,
119 count(blocker.session_id) blocks
120 from v$locked_object blocker, v$locked_object blocked
121 where blocker.XIDUSN > 0
122 and blocker.OBJECT_ID = blocked.OBJECT_ID
123 and blocked.XIDUSN = 0
124 group by blocker.session_id) blkr,
125 (select blocked.session_id sid,
126 count(blocked.session_id) blocks
127 from v$locked_object blocker, v$locked_object blocked
128 where blocker.XIDUSN > 0
129 and blocker.OBJECT_ID = blocked.OBJECT_ID
130 and blocked.XIDUSN = 0
131 group by blocked.session_id) blkd
132 where n.statistic# = se.statistic#
133 and sn.sid = se.sid
134 and n.name = 'session pga memory'
135 and io.sid = sn.sid
136 and sn.sid = blkr.sid(+)
137 and sn.sid = blkd.sid(+)
138 order by sn.sid );
139  
140 # Setup a hash of default parameters
141 my $defaultParms = {
142 Interval => 120,
143 DSN => undef,
144 User => undef,
145 Auth => undef,
146 Attr => 'Oracle',
147 VBHeader => $stdHeader,
148 VBDetail => $stdDetail,
149 VBServerURI => undef,
150 LogFile => undef,
151 LogHeader => undef,
152 LogDetail => undef,
153 RotateLogAt => undef,
154 ErrorStatus => undef,
155 SqlClause => $sql
156 };
157  
158 # Run the validation, setting defaults if values are not already set
159 $self->validateParms($defaultParms) || &fatal("Exiting");
160  
161 # Initialize a new DBI object
162 $self->SUPER::new() || return undef
163  
164 # Store the default parms
165 $self->{defaultParms} = $defaultParms;
166  
167 ($self);
168 }
169  
170 #-------------------------------------------------------------------------------
171 # Function: addVBObj
172 # Description: Add a vb object to the DBI object.
173 # Input Parms:
174 # Output Parms: None
175 #-------------------------------------------------------------------------------
176 sub addVBObj
177 {
178 my $self = shift;
179 my $DSN = $self->{DSN};
180 my $User = $self->{User};
181 my $Interval = $self->{Interval};
182 my %args = @_;
183  
184 # Setup some reasonable thresholds
185 my $expireAfterSec = int($Interval * 3);
186 my $upgradeAfterSec = int($Interval * 4);
187 my $description = qq(
188 This object monitors the users logged into '$DSN'.
189 );
190  
191 # Remove any '.' characters from the DNS and User names, so that we don't
192 # confuse the VBObject name.
193 $DSN =~ s/\./-/g;
194 $User =~ s/\./-/g;
195  
196 # Setup a hash of rules to be returned
197 my $defaultRules = {
198 VBObjName => ".$::HOST.db.$User\@$DSN.logins",
199 TextHistoryLimit => undef,
200 ReverseText => undef,
201 # Warn if any blocking occurs.
202 Rules => {
203 '$data[5] > 0' => 'Warning' },
204 Requirements => undef,
205 StatusHistoryLimit => 30,
206 StatusChangeActions => undef,
207 StatusUpgradeRules =>
208 "Upgrade to Failed if Warning occurs 3 times in $upgradeAfterSec seconds",
209 ExpireAfter => "$expireAfterSec seconds",
210 Description => $description,
211 RrdTimeCol => undef,
212 RrdColumns => undef,
213 RrdFilter => undef,
214 RrdMin => undef,
215 RrdMax => undef,
216 RrdXFF => undef,
217 RrdCF => undef,
218 RrdDST => undef,
219 };
220  
221 # Run the validation
222 &validateParms(\%args,$defaultRules) || &fatal("Exiting");
223  
224 # Add the rule
225 my $vbObj = $self->SUPER::addVBObj(%args);
226  
227 ($vbObj);
228 }
229  
230 1;
231 __END__