Commit cb59dd3a authored by ueli heuer's avatar ueli heuer 👾
Browse files

Add support for #devicename for the probe 'iostat'

parent ca2fcdce
......@@ -404,7 +404,7 @@ if (! $nodaemon ) {
close STDIN;
close STDOUT;
close STDERR;
open (STDIN, '/dev/null') or die("Can't read /dev/null: $!\n");
open (STDIN, '/dev/null') or die("Can't read /dev/null: $!\n");
if (defined($stdout) ) {
open(STDOUT,">> $stdout") or
die ("ERROR: Can't write to $stdout: $!\n");
......@@ -477,9 +477,9 @@ my $hostinfo_sql = 'select dh.snmp_location, dh.sysObjectID_id,
where dh.id = ?';
my $hostinfo_h = $db->prepare($hostinfo_sql);
my $sysObjectID_sql = 'select id
from dvg_sysObjectID
where sysObjectID = ?';
my $sysObjectID_sql = 'SELECT id
FROM dvg_sysObjectID
WHERE sysObjectID = ?';
my $sysObjectID_h = $db->prepare($sysObjectID_sql);
my $hicb_check_hwtype_sql = 'select sysObjectID_id
from dvg_host
......@@ -533,7 +533,6 @@ while ( $RUN ) {
} else {
$target = $hostname;
}
# TODO Check target if it's resolvable
$session = OpenSession($THIS_HOSTID, $target, $snmpdomain,
$snmpversion, $snmpcommunity, $username, $seclevel, $authkey,
......@@ -751,24 +750,23 @@ sub database_cb($$$) # {{{
# checke for hosts with a changed date
my $host_sql = "select dh.id, dh.name, dh.activ = 'y', dh.changed
from dvg_module dm, dvg_module_assign dma,
my $host_sql = "SELECT dh.id, dh.name, dh.activ = 'y', dh.changed
FROM dvg_module dm, dvg_module_assign dma,
dvg_host dh, dvg_device dd, dvg_probe dp
where dm.type = 'host'
and dm.name = 'device'
and dma.target_id = dh.id
/* and dh.activ = 'y' */
and dh.start_date <= curdate()
and (dh.stop_date is null or dh.stop_date >= curdate())
and dd.host_id = dh.id
and dd.activ = 'y'
and dd.start_date <= curdate()
and (dd.stop_date is null or dd.stop_date >= curdate())
and dd.probe_id = dp.id
and dp.type = 'snmp'
and dh.changed >= FROM_UNIXTIME(?)
group by dh.id";
WHERE dm.type = 'host'
AND dm.name = 'device'
AND dma.target_id = dh.id
/* AND dh.activ = 'y' */
AND dh.start_date <= curdate()
AND (dh.stop_date is null or dh.stop_date >= curdate())
AND dd.host_id = dh.id
AND dd.activ = 'y'
AND dd.start_date <= curdate()
AND (dd.stop_date is null or dd.stop_date >= curdate())
AND dd.probe_id = dp.id
AND dp.type = 'snmp'
AND dh.changed >= FROM_UNIXTIME(?)
GROUP BY dh.id";
my $host_h = $db->prepare($host_sql);
$host_h->execute($last_check);
......@@ -969,7 +967,7 @@ sub uptime_cb($$$) # {{{
if (defined($session->var_bind_list)) {
$uptime = $session->var_bind_list->{$SNMP_sysuptime};
$newhost_status = 'up';
if ($olduptime && ($uptime < $olduptime)) {
if (isint($uptime) && ($uptime < $olduptime)) {
Unix::Syslog::syslog (LOG_WARNING,
"U_CB: (%d;%s::0) has restarted; last uptime: %s",
$host_id, $session->hostname(), $olduptime);
......@@ -1127,17 +1125,21 @@ sub data_cb($$$$$$$@) # {{{
}
if ( $value_id > 0 ) {
$db->do(sprintf(
"update dvg_device_value
set last_sample = %s, delta_value = %s,
delta_time = %s, time = '%s' where id = '%s'",
if (defined($val) && defined($delta_value) && defined($delta_time) ) {
$db->do(sprintf(
"UPDATE dvg_device_value
SET last_sample = %s, delta_value = %s,
delta_time = %s, time = '%s' where id = '%s'",
$val,$delta_value,$delta_time,$now,$value_id));
}
} else {
$db->do(sprintf("insert delayed into
dvg_device_value(id,device_id,arg_id,last_sample,
delta_value,delta_time,time)
values(null,'%d','%d',%s,%s,%s,%s)",
$device_id,$n,$val,$delta_value,$delta_time,$now));
if (defined($val) && defined($delta_value) && defined($delta_time) ) {
$db->do(sprintf(
"INSERT DELAYED INTO dvg_device_value(id,device_id,
arg_id,last_sample,delta_value,delta_time,time)
VALUES(null,'%d','%d',%s,%s,%s,%s)",
$device_id,$n,$val,$delta_value,$delta_time,$now));
}
}
$n++;
}
......@@ -1466,18 +1468,19 @@ sub device2params($$$$$$) # {{{
my ($session,$device_id,$host_id,$target,$snmpversion,$hasHC) = @_;
my ($get_probe_args_h,$_probe_id, $parameter, $max_param_id, $min_param_id,
$probe_id, @dev_parameter, @PARAM_MAX, @PARAM_MIN, $param_id, $param, $value,
$max, @max, $min, @min, $absmax, $realmax, $datafile_name,
$dotraffic, $wrapnegative, $n,$i);
my ($_probe_id, $_probe_name, $absmax, $datafile_name, $dotraffic,
$get_probe_args_h, $max, $max_param_id, $min, $min_param_id, $param,
$param_id, $parameter, $probe_id, $probe_name, $realmax, $value,
$wrapnegative, @dev_parameter, @max, @min, @PARAM_MAX, @PARAM_MIN,
$n,$i);
my $get_probe_args_sql = 'select p.id, pa.oid, pa.max_param, null
from dvg_probe_args pa, dvg_probe p, dvg_device dd
where p.id = pa.probe_id
and p.type = \'snmp\'
and p.id = dd.probe_id
and dd.id = ?
order by pa.seq';
my $get_probe_args_sql = 'SELECT p.id, p.name, pa.oid, pa.max_param, null
FROM dvg_probe_args pa, dvg_probe p, dvg_device dd
WHERE p.id = pa.probe_id
AND p.type = \'snmp\'
AND p.id = dd.probe_id
AND dd.id = ?
ORDER BY pa.seq';
$get_probe_args_h = $db->prepare($get_probe_args_sql);
$get_probe_args_h->execute($device_id);
......@@ -1503,15 +1506,16 @@ sub device2params($$$$$$) # {{{
Unix::Syslog::syslog (LOG_INFO,"
d2p: ([%s;%d]::%s) %s parameter found",
$session->hostname(), $host_id, $device_id, $get_probe_args_count)
if $DEBUG;;
if $DEBUG;
}
@dev_parameter = @PARAM_MAX = @PARAM_MIN = ();
$n=0;
while ( ($_probe_id, $parameter, $max_param_id, $min_param_id) =
while ( ($_probe_id,$_probe_name,$parameter, $max_param_id, $min_param_id) =
$get_probe_args_h->fetchrow) {
$probe_id = $_probe_id;
$probe_name = $_probe_name;
$dev_parameter[$n] = $parameter;
$PARAM_MAX[$n] = $max_param_id;
$PARAM_MIN[$n] = $min_param_id;
......@@ -1541,7 +1545,7 @@ sub device2params($$$$$$) # {{{
$wrapnegative = $value;
}
for ($i=0; $i < $n; $i++) {
if ($PARAM_MAX[$i] == $param_id) {
if (defined($PARAM_MAX[$i]) && $PARAM_MAX[$i] == $param_id) {
$max[$i] = $value;
}
# TODO
......@@ -1551,10 +1555,13 @@ sub device2params($$$$$$) # {{{
}
# if $value starts with a # -> it is a Interfacename
if ( $value =~ /^#/i ) {
if ( $value =~ /^#/i && $probe_name =~ /^ifOctet/ ) {
$value = DVG_tool::get_intnum_byname($HOSTS{$host_id}{'session'},
$host_id,$device_id,$target,$value);
} elsif ($value eq '@IP' ) { # hack for the lucent pips
} elsif ( $value =~ /^#/i && $probe_name =~ /^iostat/ ) {
$value = DVG_tool::get_iodevice_byname($HOSTS{$host_id}{'session'},
$host_id,$device_id,$target,$value);
} elsif ( $value eq '@IP' ) { # hack for the lucent pips
$value = 0;
# search the IP Addresse ...
$ip_h->execute($device_id);
......
......@@ -440,7 +440,7 @@ while (<TEMPLATE>) {
my $insert_sql = "insert into dvg_host(id,name,host,loc_id,type_id,
host_group,cust_id,hw_id,rt_id,snmpversion,community,snmpport,has_HC,
start_date,stop_date,activ,check_host,user,changed,creator,
created)
created)
values (null,'$hostname','$name',$loc_id,'$type_id',
'$group_id','$cust_id',$hw_id,$rt_id,'$snmpversion',
'$community','$port','$has_HC', now(),null,'$activ','$check',
......@@ -452,8 +452,8 @@ while (<TEMPLATE>) {
printf ("New Host (%s) (id=%s) created\n",$hostname,$host_id);
if ($module_id > 0 && $host_id > 0) {
$db->do("insert into dvg_module_assign(id,module_id,target_id,
user,changed,created)
values(null,$module_id,$host_id,'$user',now(),now())");
user,creator,changed,created)
values(null,$module_id,$host_id,'$user','$user',now(),now())");
}
}
} elsif ( $ord > 0 && $host_id == 0 ) {
......@@ -470,9 +470,9 @@ while (<TEMPLATE>) {
$activ = check_yesno($activ);
$db->do("insert into dvg_device(id,host_id,ord,name,probe_id,
start_date,stop_date,activ,user,changed,created)
start_date,stop_date,activ,user,creator,changed,created)
values (null,'$host_id','$ord','$devicename','$probe_id',
now(),null,'$activ','$user',now(),now())");
now(),null,'$activ','$user','$user',now(),now())");
$device_id=$db->{'mysql_insertid'};
printf ("New Devices (%s) (id=%s) created\n",$devicename,$device_id);
......
......@@ -12,7 +12,8 @@
10:Memory:memory (ucd):y:2GB:2GB:
15:Loadaverage:Load (ucd):y:1000:1000:
15:Processes:Processes (ucd):y:1000:
20:eth0:ifOctet ifError ifDrop ifPacket:y:#eth0:125000000:125000000:y:y:
20:ens192:ifOctet ifError ifDrop ifPacket:y:#ens192:1250000000:1250000000:y:y:
20:lo:ifOctet ifError ifDrop ifPacket:y:#lo:125000000:125000000:y:y:
30:Disk /:Disk usage (linux):y:31:descr:20GB:
40:iostat sda:iostat:y:2:2000000000:2000000000:
30:Disk /:Disk usage (linux):y:31:descr:20GB:20GB:
40:iostat sda:iostat:y:2:2000000000:2000000001:
#
......@@ -69,14 +69,14 @@ function get_probename($probe_id,$USER) // {{{
global $CONFIG;
if ( $probe_id ) {
if ( isset( $probe_id )) {
$probe_name = DVG_database::getOne($CONFIG->DB,sprintf('select name
from dvg_probe
where id=\'%d\'',$probe_id));
}
if ($probe_name == '') {
DVG_interface::errorpage(DVG_interface::ERROR_WRONGPARAMETER,
sprintf(gettext('probe_id=%s is not a valid id'),$probe_id));
sprintf(gettext('probe_id="%s" is not a valid id'),$probe_id));
}
if ($USER->is_admin() ) {
return
......
#
# Copyright (C) 2003 ... 2016 Ueli Heuer
# Copyright (C) ... 2020 Ueli Heuer
#
# 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
......@@ -37,14 +37,18 @@ use vars qw( %HOST @EXPORT );
sub init($);
sub openSNMPSession ($$$$$$$$$$$$);
sub get_intnum_byname ($$$$$);
sub get_iodevice_byname ($$$$$);
sub get_intnum_byip ($$$$$);
sub datafile_name ($);
sub check_datafile ($$@);
sub create_datafile ($$@);
my ($get_interface_h,$update_interface_h,$update_interfaceid_h,
$insert_interface_h,$db_param_count_h,$host_h,$delete_interface_h,$delete_old_interface_h);
my ($db_param_count_h, $delete_interface_h, $delete_old_interface_h,
$get_host_cache_h, $get_interface_h, $host_h, $insert_host_cache_h,
$insert_interface_h, $update_host_cache_h, $update_interface_h,
$update_interfaceid_h);
my $DEBUG = 0;
# {{{ sub init
......@@ -53,24 +57,36 @@ sub init($) {
my $get_interface_sql = 'SELECT id, interface_id, device_id, macaddr, last_check
FROM dvg_host_interface
WHERE host_id=?
AND (if_name=? or if_desc=? or if_alias=?)';
WHERE host_id = ?
AND (if_name = ? or if_desc = ? or if_alias = ?)';
my $update_interfaceid_sql = 'UPDATE dvg_host_interface
SET interface_id=?,
last_check=?
SET interface_id = ?,
last_check = ?
WHERE id=?';
my $update_interface_sql = 'UPDATE dvg_host_interface
SET interface_id=?,
last_check=?,
device_id=?,
macaddr=?
SET interface_id = ?,
last_check = ?,
device_id = ?,
macaddr = ?
WHERE id=?';
my $insert_interface_sql = 'INSERT into
dvg_host_interface(id,interface_id,host_id,device_id,if_name,if_desc,if_alias,macaddr,last_check)
values(null,?,?,?,?,?,?,?,?)';
my $delete_interface_sql = 'delete from dvg_host_interface where id = ?';
my $delete_old_interface_sql = 'delete from dvg_host_interface
where host_id = ? and last_check <= ?';
my $insert_interface_sql = 'INSERT INTO
dvg_host_interface(id,interface_id,host_id,device_id,if_name,if_desc,if_alias,macaddr,last_check)
VALUES(null,?,?,?,?,?,?,?,?)';
my $delete_interface_sql = 'DELETE FROM dvg_host_interface WHERE id = ?';
my $delete_old_interface_sql = 'DELETE FROM dvg_host_interface
WHERE host_id = ?
AND last_check <= ?';
my $get_host_cache_sql = 'SELECT id, device_id, value
FROM dvg_host_cache
WHERE host_id = ?
AND device_id = ?';
my $update_host_cache_sql = 'UPDATE dvg_host_cache
SET value = ?,
name = ?
WHERE id = ?';
my $insert_host_cache_sql = 'INSERT INTO dvg_host_cache(id,host_id,device_id,value,name)
VALUES(null,?,?,?,?)';
$get_interface_h = $db->prepare($get_interface_sql);
$update_interfaceid_h = $db->prepare($update_interfaceid_sql);
......@@ -79,15 +95,19 @@ sub init($) {
$delete_interface_h = $db->prepare($delete_interface_sql);
$delete_old_interface_h = $db->prepare($delete_old_interface_sql);
my $db_param_count_sql = 'select oid_type
from dvg_probe_args
where probe_id = ?
order by seq';
$get_host_cache_h = $db->prepare($get_host_cache_sql);
$update_host_cache_h = $db->prepare($update_host_cache_sql);
$insert_host_cache_h = $db->prepare($insert_host_cache_sql);
my $db_param_count_sql = 'SELECT oid_type
FROM dvg_probe_args
WHERE probe_id = ?
ORDER by seq';
$db_param_count_h = $db->prepare($db_param_count_sql);
my $host_sql = 'select snmpdomain, snmpversion, snmpport, snmptimeout,
my $host_sql = 'SELECT snmpdomain, snmpversion, snmpport, snmptimeout,
snmpretries
from dvg_host where id = ?';
FROM dvg_host WHERE id = ?';
$host_h = $db->prepare($host_sql);
}
......@@ -154,12 +174,15 @@ sub _get_interfaces # {{{
$host_id, $interface);# if $DEBUG > 2;
$result_id = undef;
$ifindex = $ifdescr = $ifname = $ifalias = $ifmacaddr = undef;
Unix::Syslog::syslog(LOG_DEBUG, '_get_interfaces: SNMP START (%s)',$host_id);
$vars = new SNMP::VarList(['ifIndex'],['ifDescr'],['ifName'],['ifAlias'],['ifPhysAddress']);
($ifindex, $ifdescr, $ifname, $ifalias, $ifmacaddr) = $session->getnext($vars);
# delete all dvg_host_interface entries of the current host
$delete_old_interface_h->execute($host_id,0);
$ifindex = $ifdescr = $ifname = $ifalias = $ifmacaddr = undef;
Unix::Syslog::syslog(LOG_DEBUG, '_get_interfaces: SNMP START (%s)',$host_id);
$vars = new SNMP::VarList(['ifIndex'],['ifDescr'],['ifName'],['ifAlias'],['ifPhysAddress']);
($ifindex, $ifdescr, $ifname, $ifalias, $ifmacaddr) = $session->getnext($vars);
Unix::Syslog::syslog(LOG_DEBUG, '_get_interfaces: SNMP DONE (%s)',$host_id);
Unix::Syslog::syslog(LOG_DEBUG, '_get_interfaces: SNMP DONE (%s)',$host_id);
if ( $session->{ErrorStr} ) {
Unix::Syslog::syslog(LOG_DEBUG,
......@@ -226,9 +249,9 @@ sub _get_interfaces # {{{
}
# delete old dvg_host_interface entries of the current host.
$delete_old_interface_h->execute($host_id,
time() - DVG_config::interface_max_unchecked_time());
# # delete old dvg_host_interface entries of the current host.
# $delete_old_interface_h->execute($host_id,
# time() - DVG_config::interface_max_unchecked_time());
return $result_id;
} # }}}
......@@ -307,6 +330,51 @@ sub get_intnum_byname ($$$$$) {
return $result_id;
}
# }}}
# {{{ sub get_iodevice_byname ($session,host_id,$device_id,$host,$devicename)
sub get_iodevice_byname ($$$$$) {
my ($session,$host_id,$device_id,$host,$devicename) = @_;
my ($diskIODevice, $diskIOIndex, $result_id, $vars, $cache_id, $value);
$devicename =~ s/^#//; # drop '#'
$diskIODevice = $diskIOIndex = undef;
Unix::Syslog::syslog(LOG_DEBUG, 'get_iodevice_byname: SNMP START (%s:%s)',$host_id,$devicename);
$vars = new SNMP::VarList(['diskIODevice'],['diskIOIndex']);
($diskIODevice, $diskIOIndex) = $session->getnext($vars);
if ( $session->{ErrorStr} ) {
Unix::Syslog::syslog(LOG_DEBUG,
"get_iodevice_byname getnext_error %s (host_id=%d, devicename=%s)",
$session->{ErrorStr}, $host_id, $devicename);
}
while (!$session->{ErrorStr} and $$vars[0]->tag eq 'diskIODevice') {
if ($diskIODevice eq $devicename) {
$result_id = $diskIOIndex;
}
($diskIODevice, $diskIOIndex) = $session->getnext($vars);
}
Unix::Syslog::syslog(LOG_DEBUG, 'get_iodevice_byname: SNMP DONE (%s)',$host_id);
Unix::Syslog::syslog(LOG_DEBUG, 'devicename(%s)=%d',$devicename,$result_id);
$get_host_cache_h->execute($host_id,$device_id);
if ($get_host_cache_h->rows == 1) {
($cache_id, $value) =
$get_host_cache_h->fetchrow;
}
if ( defined($cache_id) ) {
if ($value != $result_id) {
$update_host_cache_h->execute($result_id,$devicename,$cache_id);
}
} else {
$insert_host_cache_h->execute($host_id,$device_id,$result_id,$devicename);
}
return $result_id;
}
#}}}
# {{{ sub get_intnum_byip ($host_id,$host,$community,$ip)
sub get_intnum_byip ($$$$$) {
my ($session,$host_id,$device_id,$host,$ip) = @_;
......@@ -316,12 +384,12 @@ sub get_intnum_byip ($$$$$) {
$hi_id = 0;
Unix::Syslog::syslog(LOG_INFO,'get_intnum_byip: %d,%s->%s',
Unix::Syslog::syslog(LOG_DEBUG,'get_intnum_byip: %d,%s->%s',
$host_id,$host,$ip);
$ifindex = $session->get(sprintf('ipRouteIfIndex.%s,',$ip));
if ( $ifindex ) {
Unix::Syslog::syslog(LOG_INFO,'get_intnum_byip: (%s):@ip(%s) ifindex=%s',
Unix::Syslog::syslog(LOG_DEBUG,'get_intnum_byip: (%s):@ip(%s) ifindex=%s',
$host_id, $ip, $ifindex);
if ( $hi_id ) {
Unix::Syslog::syslog(LOG_DEBUG,'4: update_interface(%d,%d,%d,"%s",%d)',$ifindex, time(), $device_id,'null',$hi_id);
......@@ -334,7 +402,7 @@ sub get_intnum_byip ($$$$$) {
return $ifindex;
} else {
Unix::Syslog::syslog(LOG_INFO,'get_intnum_byip: (%s):@ip(%s) index ' .
Unix::Syslog::syslog(LOG_DEBUG,'get_intnum_byip: (%s):@ip(%s) index ' .
'notfound :(',$host_id, $ip);
}
return undef;
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment