/usr/share/cricket/lib/sql.pm is in cricket 1.0.5-20.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # -*-perl-*-
# Cricket: a configuration, polling and data display wrapper for RRD files
#
# Copyright (C) 1998 Jeff R. Allen and WebTV Networks, Inc.
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
use Common::Log;
use Common::Util;
use DBI;
use sqlUtils;
use strict;
$main::gDSFetch{'sql'} = \&sqlFetch;
sub sqlFetch {
my($dsList, $name, $target) = @_;
my @results;
my %sqlFetches;
foreach my $line (@{$dsList}) {
my @components = split(/:/, $line, 6);
my ($index, $login, $password, $query, $col, $dbdriver);
if($#components+1 < 6) {
Error("Malformed datasource line: $line.");
return();
}
$index = shift(@components);
$login = shift(@components) || 'anonymous';
$password = shift(@components) || '';
$query = shift(@components) || missing("sql query", $line);
$col = shift(@components) || 1;
$dbdriver = shift(@components) || missing("db driver", $line);
$sqlFetches{$index} = "$login:$password:$query:$col:$dbdriver";
}
DSLOOP: while(my ($index, $ilRef) = each %sqlFetches) {
my($login, $password, $query, $col, $dbdriver) = split(/:/, $ilRef, 5);
my $matches;
my $value;
my $dbh = DBI->connect($dbdriver, $login, $password) || Error();
my $sth = $dbh->prepare($query);
if($sth->errstr) {
Error "Bad query: $sth->errstr";
}
$sth->execute;
if($sth->errstr) {
Error "Bad result: $sth->errstr";
}
my @row = $sth->fetchrow_array();
$value = $row[$col-1];
$matches++;
if($sth->fetchrow_array()) {
$matches++;
}
if($matches < 1) {
push @results, "$index:U";
} else {
push @results, "$index:$value";
}
}
return @results;
}
1;
# Local Variables:
# mode: perl
# indent-tabs-mode: nil
# tab-width: 4
# perl-indent-level: 4
# End:
|