File: sqlconn.monitor

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 (69 lines) | stat: -rw-r--r-- 1,572 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
#!/usr/bin/perl -w
#
# Monitor sqlnet connection
#
# Arguments are: names of databases (as understood by listener)
#
# Available under the same terms as perl itself if distributed alone.
#
#
use Local::Env; # local environment variable setting
use DBI;

$dbuser = $ENV{ORACLE_USERID}; # from Local::Env or set it explicitly

foreach $dbname (@ARGV) {

unless (
    eval {
        $dbh = DBI->connect("dbi:Oracle:$dbname", $dbuser, '',
                                { RaiseError => 1, AutoCommit => 1 })
    }

)
    {
        push @failures, "$dbname connect";
        push @longerr, "$dbname: $DBI::errstr";
        $retval++;
        next
    } 

unless ( $sth = $dbh->prepare("select sysdate from sys.dual") )
    {
        push @failures, "$dbname prepare";
        push @longerr, "$dbname: $dbh->errstr";
        $retval++;
        next
    } 
unless ( $sth->execute()                                      )
    {
        push @failures, "$dbname execute";
        push @longerr, "$dbname: $dbh->errstr";
        $retval++;
        next
    } 
unless ( $sth->finish()                                       )
    {
        push @failures, "$dbname finish";
        push @longerr, "$dbname: $dbh->errstr";
        $retval++;
        next
    } 

unless ( $dbh->disconnect                                     )
    {
        push @failures, "$dbname disconnect";
        push @longerr, "$dbname: $dbh->errstr";
        $retval++;
        next
    } 
}


if (@failures) {
    print join (", ", @failures), "\n";
    print join ("\n", @longerr), "\n";
}

exit $retval;