2010-02-15 01:26:50 +00:00
< ? php
2010-07-07 14:55:21 +00:00
function discover_sensor ( & $valid , $class , $device , $oid , $index , $type , $descr , $precision = 1 , $low_limit = NULL , $low_warn_limit = NULL , $warn_limit = NULL , $high_limit = NULL , $current = NULL )
{
global $config , $debug ;
if ( $debug ) { echo ( " $oid , $index , $type , $descr , $precision\n " ); }
if ( ! $low_limit )
{
$low_limit = $config [ 'limit' ][ 'current' ];
}
2010-07-15 21:39:58 +00:00
if ( mysql_result ( mysql_query ( " SELECT count(sensor_id) FROM `sensors` WHERE sensor_class=' " . mres ( $class ) . " ' AND device_id = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " ), 0 ) == '0' )
2010-07-07 14:55:21 +00:00
{
$query = " INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_limit_warn`, `sensor_limit_low`, `sensor_limit_low_warn`, `sensor_current`) " ;
$query .= " VALUES (' " . mres ( $class ) . " ', ' " . $device [ 'device_id' ] . " ', ' $oid ', ' $index ', ' $type ', ' $descr ', ' $precision ', ' $high_limit ', ' $warn_limit ', ' $low_limit ', ' $low_warn_limit ', ' $current ') " ;
mysql_query ( $query );
if ( $debug ) { echo ( " $query " . mysql_affected_rows () . " inserted " ); }
echo ( " + " );
}
else
{
$sensor_entry = mysql_fetch_array ( mysql_query ( " SELECT * FROM `sensors` WHERE sensor_class=' " . mres ( $class ) . " ' AND device_id = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " ));
if ( $oid == $sensor_entry [ 'sensor_oid' ] && $descr == $sensor_entry [ 'sensor_descr' ] && $precision == $sensor_entry [ 'sensor_precision' ])
{
echo ( " . " );
}
else
{
mysql_query ( " UPDATE sensors SET `sensor_descr` = ' $descr ', `sensor_oid` = ' $oid ', `sensor_precision` = ' $precision ' WHERE `sensor_class` = ' " . mres ( $class ) . " ' AND `device_id` = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " );
echo ( " U " );
if ( $debug ) { echo ( " $query " . mysql_affected_rows () . " updated " ); }
}
}
$valid [ $type ][ $index ] = 1 ;
return $return ;
}
2010-02-28 22:04:15 +00:00
2010-06-17 10:14:53 +00:00
function discover_juniAtmVp ( & $valid , $interface_id , $vp_id , $vp_descr )
2010-03-11 19:09:19 +00:00
{
global $config , $debug ;
2010-02-28 22:04:15 +00:00
2010-03-11 19:09:19 +00:00
if ( mysql_result ( mysql_query ( " SELECT COUNT(*) FROM `juniAtmVp` WHERE `interface_id` = ' " . $interface_id . " ' AND `vp_id` = ' " . $vp_id . " ' " ), 0 ) == " 0 " )
{
$sql = " INSERT INTO `juniAtmVp` (`interface_id`,`vp_id`,`vp_descr`) VALUES (' " . $interface_id . " ',' " . $vp_id . " ',' " . $vp_descr . " ') " ;
mysql_query ( $sql ); echo ( " + " );
if ( $debug ) { echo ( $sql . " - " . mysql_affected_rows () . " inserted " ); }
}
else
{
echo ( " . " );
}
2010-06-17 10:14:53 +00:00
$valid [ $interface_id ][ $vp_id ] = 1 ;
2010-02-28 22:04:15 +00:00
}
2010-03-11 19:09:19 +00:00
function discover_link ( $local_interface_id , $protocol , $remote_interface_id , $remote_hostname , $remote_port , $remote_platform , $remote_version )
{
global $config , $debug , $link_exists ;
2010-02-15 23:56:30 +00:00
2010-03-11 19:09:19 +00:00
if ( mysql_result ( mysql_query ( " SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ' $remote_hostname ' AND `local_interface_id` = ' $local_interface_id '
2010-02-15 23:56:30 +00:00
AND `protocol` = '$protocol' AND `remote_port` = '$remote_port' " ),0) == " 0 " )
2010-03-11 19:09:19 +00:00
{
$sql = " INSERT INTO `links` (`local_interface_id`,`protocol`,`remote_interface_id`,`remote_hostname`,`remote_port`,`remote_platform`,`remote_version`)
2010-02-15 23:56:30 +00:00
VALUES ( '$local_interface_id' , '$protocol' , '$remote_interface_id' , '$remote_hostname' , '$remote_port' , '$remote_platform' , '$remote_version' ) " ;
2010-03-11 19:09:19 +00:00
mysql_query ( $sql );
echo ( " + " ); if ( $debug ) { echo ( " $sql " ); }
}
else
{
$data = mysql_fetch_array ( mysql_query ( " SELECT * FROM `links` WHERE `remote_hostname` = ' $remote_hostname ' AND `local_interface_id` = ' $local_interface_id '
2010-02-15 23:56:30 +00:00
AND `protocol` = '$protocol' AND `remote_port` = '$remote_port' " ));
2010-03-11 19:09:19 +00:00
if ( $data [ 'remote_interface_id' ] == $remote_interface_id && $data [ 'remote_platform' ] == $remote_platform && $remote_version == $remote_version )
{
echo ( " . " );
}
else
{
$sql = " UPDATE `links` SET `remote_interface_id` = $remote_interface_id , `remote_platform` = ' $remote_platform ', `remote_version` = ' $remote_version ' WHERE `id` = ' " . $data [ 'id' ] . " ' " ;
mysql_query ( $sql );
echo ( " U " ); if ( $debug ) { echo ( " $sql " );}
}
}
$link_exists [ $local_interface_id ][ $remote_hostname ][ $remote_port ] = 1 ;
2010-02-15 23:56:30 +00:00
}
2010-06-17 10:14:53 +00:00
function discover_storage ( & $valid , $device , $index , $type , $mib , $descr , $size , $units , $used = NULL )
2010-03-11 19:09:19 +00:00
{
global $config , $debug ;
if ( $debug ) { echo ( " $device , $index , $type , $mib , $descr , $units , $used , $size\n " ); }
if ( $descr && $size > " 0 " )
{
if ( mysql_result ( mysql_query ( " SELECT count(storage_id) FROM `storage` WHERE `storage_index` = ' $index ' AND `device_id` = ' " . $device [ 'device_id' ] . " ' AND `storage_mib` = ' $mib ' " ), 0 ) == '0' )
{
$query = " INSERT INTO storage (`device_id`, `storage_descr`, `storage_index`, `storage_mib`, `storage_type`, `storage_units`,`storage_size`,`storage_used`)
2010-02-24 13:46:12 +00:00
values ( '".$device[' device_id ']."' , '$descr' , '$index' , '$mib' , '$type' , '$units' , '$size' , '$used' ) " ;
2010-03-11 19:09:19 +00:00
mysql_query ( $query );
if ( $debug ) { print $query . " \n " ; mysql_error (); }
echo ( " + " );
}
else
{
echo ( " . " );
$query = " UPDATE `storage` SET `storage_descr` = ' " . $descr . " ', `storage_type` = ' " . $type . " ', `storage_units` = ' " . $units . " ', `storage_size` = ' " . $size . " '
2010-02-24 13:46:12 +00:00
WHERE `device_id` = '".$device[' device_id ']."' AND `storage_index` = '".$index."' AND `storage_mib` = '".$mib."' " ;
2010-03-11 19:09:19 +00:00
mysql_query ( $query );
if ( $debug ) { print $query . " \n " ; }
}
2010-06-17 10:14:53 +00:00
$valid [ $mib ][ $index ] = 1 ;
2010-03-11 19:09:19 +00:00
}
2010-02-24 13:46:12 +00:00
}
2010-06-17 10:14:53 +00:00
function discover_processor ( & $valid , $device , $oid , $index , $type , $descr , $precision = " 1 " , $current = NULL , $entPhysicalIndex = NULL , $hrDeviceIndex = NULL )
2010-03-11 19:09:19 +00:00
{
global $config , $debug ;
if ( $debug ) { echo ( " $device , $oid , $index , $type , $descr , $precision , $current , $entPhysicalIndex , $hrDeviceIndex\n " ); }
if ( $descr )
{
$descr = str_replace ( " \" " , " " , $descr );
if ( mysql_result ( mysql_query ( " SELECT count(processor_id) FROM `processors` WHERE `processor_index` = ' $index ' AND `device_id` = ' " . $device [ 'device_id' ] . " ' AND `processor_type` = ' $type ' " ), 0 ) == '0' )
{
$query = " INSERT INTO processors (`entPhysicalIndex`, `hrDeviceIndex`, `device_id`, `processor_descr`, `processor_index`, `processor_oid`, `processor_usage`, `processor_type`, `processor_precision`)
2010-02-21 02:44:00 +00:00
values ( '$entPhysicalIndex' , '$hrDeviceIndex' , '".$device[' device_id ']."' , '$descr' , '$index' , '$oid' , '$current' , '$type' , '$precision' ) " ;
2010-03-11 19:09:19 +00:00
mysql_query ( $query );
if ( $debug ) { print $query . " \n " ; }
echo ( " + " );
}
else
{
echo ( " . " );
2010-07-09 14:04:05 +00:00
$query = " UPDATE `processors` SET `processor_descr` = ' " . $descr . " ', `processor_oid` = ' " . $oid . " ', `processor_precision` = ' " . $precision . " '
2010-02-21 01:35:13 +00:00
WHERE `device_id` = '".$device[' device_id ']."' AND `processor_index` = '".$index."' AND `processor_type` = '".$type."' " ;
2010-03-11 19:09:19 +00:00
mysql_query ( $query );
if ( $debug ) { print $query . " \n " ; }
}
2010-02-15 23:56:30 +00:00
2010-06-17 10:14:53 +00:00
$valid [ $type ][ $index ] = 1 ;
2010-03-11 19:09:19 +00:00
}
}
2010-02-22 00:57:13 +00:00
2010-06-17 10:14:53 +00:00
function discover_mempool ( & $valid , $device , $index , $type , $descr , $precision = " 1 " , $entPhysicalIndex = NULL , $hrDeviceIndex = NULL )
2010-03-11 19:09:19 +00:00
{
global $config , $debug ;
if ( $debug ) { echo ( " $device , $oid , $index , $type , $descr , $precision , $current , $entPhysicalIndex , $hrDeviceIndex\n " ); }
if ( $descr )
{
if ( mysql_result ( mysql_query ( " SELECT count(mempool_id) FROM `mempools` WHERE `mempool_index` = ' $index ' AND `device_id` = ' " . $device [ 'device_id' ] . " ' AND `mempool_type` = ' $type ' " ), 0 ) == '0' )
{
$query = " INSERT INTO mempools (`entPhysicalIndex`, `hrDeviceIndex`, `device_id`, `mempool_descr`, `mempool_index`, `mempool_type`, `mempool_precision`)
2010-02-22 00:57:13 +00:00
values ( '$entPhysicalIndex' , '$hrDeviceIndex' , '".$device[' device_id ']."' , '$descr' , '$index' , '$type' , '$precision' ) " ;
2010-03-11 02:53:17 +00:00
mysql_query ( $query );
2010-03-11 19:09:19 +00:00
if ( $debug ) { print $query . " \n " ; }
echo ( " + " );
}
else
{
echo ( " . " );
# entry = mysql_fetch_assoc(mysql_query());
2010-03-26 18:34:21 +00:00
$query = " UPDATE `mempools` SET `mempool_descr` = ' " . $descr . " ', `entPhysicalIndex` = ' " . $entPhysicalIndex . " ' " ;
2010-03-26 18:30:27 +00:00
$query .= " , `hrDeviceIndex` = ' $hrDeviceIndex ' " ;
$query .= " WHERE `device_id` = ' " . $device [ 'device_id' ] . " ' AND `mempool_index` = ' " . $index . " ' AND `mempool_type` = ' " . $type . " ' " ;
2010-03-11 19:09:19 +00:00
mysql_query ( $query );
if ( $debug ) { print $query . " \n " ; }
}
2010-06-17 10:14:53 +00:00
$valid [ $type ][ $index ] = 1 ;
2010-03-11 19:09:19 +00:00
}
2010-02-22 00:57:13 +00:00
}
2010-06-17 10:14:53 +00:00
function discover_temperature ( & $valid , $device , $oid , $index , $type , $descr , $precision = 1 , $low_limit = NULL , $high_limit = NULL , $current )
2010-03-05 03:54:35 +00:00
{
2010-03-13 16:52:03 +00:00
global $config , $debug ;
2010-06-12 15:17:38 +00:00
if ( $debug ) { echo ( " $oid , $index , $type , $descr , $precision , $current\n " ); }
2010-03-13 16:52:03 +00:00
2010-06-25 22:12:56 +00:00
if ( mysql_result ( mysql_query ( " SELECT COUNT(sensor_id) FROM `sensors` WHERE sensor_class='temperature' AND sensor_type = ' $type ' AND sensor_index = ' $index ' AND device_id = ' " . $device [ 'device_id' ] . " ' " ), 0 ) == '0' )
2010-03-11 19:09:19 +00:00
{
2010-06-25 22:12:56 +00:00
$query = " INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_type`,`sensor_index`,`sensor_oid`, `sensor_descr`, `sensor_limit`, `sensor_current`, `sensor_precision`) " ;
$query .= " values ('temperature',' " . $device [ 'device_id' ] . " ', ' $type ',' $index ',' $oid ', ' $descr ',' " . ( $high_limit ? $high_limit : $config [ 'defaults' ][ 'sensor_limit' ]) . " ', ' $current ', ' $precision ') " ;
2010-03-11 19:09:19 +00:00
mysql_query ( $query );
echo ( " + " );
}
else
{
2010-06-25 22:12:56 +00:00
$entry = mysql_fetch_array ( mysql_query ( " SELECT * FROM `sensors` WHERE sensor_class='temperature' AND device_id = ' " . $device [ 'device_id' ] . " ' AND `sensor_type` = ' $type ' AND `sensor_index` = ' $index ' " ));
2010-03-11 19:09:19 +00:00
echo ( mysql_error ());
2010-06-25 22:12:56 +00:00
if ( $oid == $entry [ 'sensor_oid' ] && $descr == $entry [ 'sensor_descr' ] && $precision == $entry [ 'sensor_precision' ])
2010-03-11 19:09:19 +00:00
{
echo ( " . " );
}
else
{
2010-06-25 23:16:04 +00:00
mysql_query ( " UPDATE sensors SET `sensor_descr` = ' $descr ', `sensor_oid` = ' $oid ', `sensor_precision` = ' $precision ' WHERE `sensor_class` = 'temperature' AND`sensor_id` = ' " . $entry [ 'sensor_id' ] . " ' " );
2010-03-11 19:09:19 +00:00
echo ( " U " );
}
}
2010-06-17 10:14:53 +00:00
$valid [ $type ][ $index ] = 1 ;
2010-03-11 19:09:19 +00:00
return $return ;
2010-03-05 03:54:35 +00:00
}
2010-02-22 00:57:13 +00:00
2010-06-17 10:14:53 +00:00
function discover_fan ( & $valid , $device , $oid , $index , $type , $descr , $precision = 1 , $low_limit = NULL , $high_limit = NULL , $current = NULL )
2010-03-11 19:09:19 +00:00
{
global $config , $debug ;
if ( $debug ) { echo ( " $oid , $index , $type , $descr , $precision\n " ); }
if ( ! $low_limit )
{
$low_limit = $config [ 'limit' ][ 'fan' ];
}
2010-06-25 23:16:04 +00:00
if ( mysql_result ( mysql_query ( " SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='fanspeed' AND device_id = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " ), 0 ) == '0' )
2010-03-11 19:09:19 +00:00
{
2010-06-25 23:16:04 +00:00
$query = " INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_current`) " ;
$query .= " VALUES ('fanspeed',' " . $device [ 'device_id' ] . " ', ' $oid ', ' $index ', ' $type ', ' $descr ', ' $precision ', ' $low_limit ', ' $current ') " ;
2010-03-11 19:09:19 +00:00
mysql_query ( $query );
echo ( " + " );
}
else
{
2010-06-25 23:16:04 +00:00
$fan_entry = mysql_fetch_array ( mysql_query ( " SELECT * FROM `sensors` WHERE sensor_class='fanspeed' AND device_id = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " ));
if ( $oid == $fan_entry [ 'sensor_oid' ] && $descr == $fan_entry [ 'sensor_descr' ] && $precision == $fan_entry [ 'sensor_precision' ])
2010-03-11 19:09:19 +00:00
{
echo ( " . " );
}
else
{
2010-07-07 13:58:11 +00:00
mysql_query ( " UPDATE sensors SET `sensor_descr` = ' $descr ', `sensor_oid` = ' $oid ', `sensor_precision` = ' $precision ' WHERE `sensor_class` = 'fanspeed' AND `device_id` = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " );
2010-03-11 19:09:19 +00:00
echo ( " U " );
}
}
2010-06-17 10:14:53 +00:00
$valid [ $type ][ $index ] = 1 ;
2010-03-11 19:09:19 +00:00
return $return ;
2010-02-15 01:26:50 +00:00
}
2010-06-17 10:14:53 +00:00
function discover_volt ( & $valid , $device , $oid , $index , $type , $descr , $precision = 1 , $low_limit = NULL , $high_limit = NULL , $current = NULL )
2010-03-11 19:09:19 +00:00
{
global $config , $debug ;
if ( $debug ) { echo ( " $oid , $index , $type , $descr , $precision\n " ); }
if ( ! $low_limit )
{
$low_limit = $config [ 'limit' ][ 'volt' ];
}
2010-07-07 13:58:11 +00:00
if ( mysql_result ( mysql_query ( " SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='voltage' AND device_id = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " ), 0 ) == '0' )
2010-03-11 19:09:19 +00:00
{
2010-06-12 15:56:37 +00:00
if ( ! $high_limit && isset ( $current )) { $high_limit = round ( $current * 1.05 , 2 ); }
if ( ! $low_limit && isset ( $current )) { $low_limit = round ( $current * 0.95 , 2 ); }
2010-07-07 13:58:11 +00:00
$query = " INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_limit_low`, `sensor_current`) " ;
$query .= " VALUES ('voltage',' " . $device [ 'device_id' ] . " ', ' $oid ', ' $index ', ' $type ', ' $descr ', ' $precision ', ' $high_limit ', ' $low_limit ', ' $current ') " ;
2010-03-11 19:09:19 +00:00
mysql_query ( $query );
if ( $debug ) { echo ( " $query " . mysql_affected_rows () . " inserted " ); }
echo ( " + " );
}
else
{
2010-06-12 15:56:37 +00:00
2010-07-07 13:58:11 +00:00
$volt_entry = mysql_fetch_array ( mysql_query ( " SELECT * FROM `sensors` WHERE sensor_class='voltage' AND device_id = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " ));
2010-06-12 15:56:37 +00:00
if ( ! isset ( $current ) && isset ( $volt_entry [ 'current' ])) { $current = $volt_entry [ 'current' ]; }
2010-07-07 13:58:11 +00:00
if ( ! $high_limit && ! $volt_entry [ 'sensor_limit' ] && $current ) { $high_limit = round ( $current * 1.05 , 2 ); } elseif ( ! $high_limit && $volt_entry [ 'sensor_limit' ]) { $high_limit = $volt_entry [ 'sensor_limit' ]; }
if ( ! $low_limit && ! $volt_entry [ 'sensor_limit_low' ] && $current ) { $low_limit = round ( $current * 0.95 , 2 ); } elseif ( ! $low_limit && $volt_entry [ 'sensor_limit_low' ]) { $low_limit = $volt_entry [ 'sensor_limit_low' ]; }
2010-06-12 15:56:37 +00:00
2010-07-07 13:58:11 +00:00
if ( $oid == $volt_entry [ 'sensor_oid' ] && $descr == $volt_entry [ 'sensor_descr' ] && $precision == $volt_entry [ 'sensor_precision' ] && $volt_entry [ 'sensor_limit' ] == $high_limit && $volt_entry [ 'sensor_limit_low' ] == $low_limit )
2010-03-11 19:09:19 +00:00
{
echo ( " . " );
}
else
{
2010-07-07 13:58:11 +00:00
$sql = " UPDATE sensors SET `sensor_descr` = ' $descr ', `sensor_oid` = ' $oid ', `sensor_precision` = ' $precision ', `sensor_limit_low` = ' $low_limit ', `sensor_limit` = ' $high_limit ' WHERE `sensor_class` = 'voltage' AND `device_id` = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " ;
2010-06-12 15:56:37 +00:00
$query = mysql_query ( $sql );
2010-03-11 19:09:19 +00:00
echo ( " U " );
2010-06-12 15:56:37 +00:00
if ( $debug ) { echo ( " $sql " . mysql_affected_rows () . " updated " ); }
2010-03-11 19:09:19 +00:00
}
}
2010-06-17 10:14:53 +00:00
$valid [ $type ][ $index ] = 1 ;
2010-03-11 19:09:19 +00:00
return $return ;
2010-02-15 05:07:18 +00:00
}
2010-06-17 10:14:53 +00:00
function discover_freq ( & $valid , $device , $oid , $index , $type , $descr , $precision = 1 , $low_limit = NULL , $high_limit = NULL , $current = NULL )
2010-06-03 10:23:11 +00:00
{
global $config , $debug ;
if ( $debug ) { echo ( " $oid , $index , $type , $descr , $precision\n " ); }
if ( ! $low_limit )
{
$low_limit = $config [ 'limit' ][ 'freq' ];
}
if ( mysql_result ( mysql_query ( " SELECT count(freq_id) FROM `frequency` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND freq_type = ' $type ' AND `freq_index` = ' $index ' " ), 0 ) == '0' )
{
2010-06-17 10:03:50 +00:00
if ( ! $high_limit && isset ( $current )) { $high_limit = round ( $current * 1.05 , 0 ); }
if ( ! $low_limit && isset ( $current )) { $low_limit = round ( $current * 0.95 , 0 ); }
2010-06-03 10:23:11 +00:00
$query = " INSERT INTO frequency (`device_id`, `freq_oid`, `freq_index`, `freq_type`, `freq_descr`, `freq_precision`, `freq_limit`, `freq_limit_low`, `freq_current`) " ;
$query .= " VALUES (' " . $device [ 'device_id' ] . " ', ' $oid ', ' $index ', ' $type ', ' $descr ', ' $precision ', ' $high_limit ', ' $low_limit ', ' $current ') " ;
mysql_query ( $query );
if ( $debug ) { echo ( " $query " . mysql_affected_rows () . " inserted " ); }
echo ( " + " );
}
else
{
$freq_entry = mysql_fetch_array ( mysql_query ( " SELECT * FROM `frequency` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND freq_type = ' $type ' AND `freq_index` = ' $index ' " ));
if ( $oid == $freq_entry [ 'freq_oid' ] && $descr == $freq_entry [ 'freq_descr' ] && $precision == $freq_entry [ 'freq_precision' ])
{
echo ( " . " );
}
else
{
mysql_query ( " UPDATE frequency SET `freq_descr` = ' $descr ', `freq_oid` = ' $oid ', `freq_precision` = ' $precision ' WHERE `device_id` = ' " . $device [ 'device_id' ] . " ' AND freq_type = ' $type ' AND `freq_index` = ' $index ' " );
echo ( " U " );
if ( $debug ) { echo ( " $query " . mysql_affected_rows () . " updated " ); }
}
}
2010-06-17 10:14:53 +00:00
$valid [ $type ][ $index ] = 1 ;
2010-06-03 10:23:11 +00:00
return $return ;
}
2010-06-23 15:54:56 +00:00
function discover_humidity ( & $valid , $device , $oid , $index , $type , $descr , $precision = 1 , $low_limit = NULL , $low_warn_limit = NULL , $warn_limit = NULL , $high_limit = NULL , $current = NULL )
{
2010-07-07 14:55:21 +00:00
return discover_sensor ( $valid , 'humidity' , $device , $oid , $index , $type , $descr , $precision , $low_limit , $low_warn_limit , $warn_limit , $high_limit , $current );
2010-06-23 15:54:56 +00:00
}
2010-06-17 10:46:04 +00:00
function discover_current ( & $valid , $device , $oid , $index , $type , $descr , $precision = 1 , $low_limit = NULL , $warn_limit = NULL , $high_limit = NULL , $current = NULL )
2010-06-09 20:03:16 +00:00
{
global $config , $debug ;
if ( $debug ) { echo ( " $oid , $index , $type , $descr , $precision\n " ); }
if ( ! $low_limit )
{
$low_limit = $config [ 'limit' ][ 'current' ];
}
2010-07-07 14:34:44 +00:00
if ( mysql_result ( mysql_query ( " SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='current' AND device_id = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " ), 0 ) == '0' )
2010-06-09 20:03:16 +00:00
{
2010-07-07 14:34:44 +00:00
$query = " INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_limit_warn`, `sensor_limit_low`, `sensor_current`) " ;
$query .= " VALUES ('current', ' " . $device [ 'device_id' ] . " ', ' $oid ', ' $index ', ' $type ', ' $descr ', ' $precision ', ' $high_limit ', ' $warn_limit ', ' $low_limit ', ' $current ') " ;
2010-06-09 20:03:16 +00:00
mysql_query ( $query );
if ( $debug ) { echo ( " $query " . mysql_affected_rows () . " inserted " ); }
echo ( " + " );
}
else
{
2010-07-07 14:34:44 +00:00
$current_entry = mysql_fetch_array ( mysql_query ( " SELECT * FROM `sensors` WHERE sensor_class='current' AND device_id = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " ));
if ( $oid == $current_entry [ 'sensor_oid' ] && $descr == $current_entry [ 'sensor_descr' ] && $precision == $current_entry [ 'sensor_precision' ])
2010-06-09 20:03:16 +00:00
{
echo ( " . " );
}
else
{
2010-07-13 10:31:46 +00:00
mysql_query ( " UPDATE sensors SET `sensor_descr` = ' $descr ', `sensor_oid` = ' $oid ', `sensor_precision` = ' $precision ' WHERE `sensor_class`='current' AND `device_id` = ' " . $device [ 'device_id' ] . " ' AND sensor_type = ' $type ' AND `sensor_index` = ' $index ' " );
2010-06-09 20:03:16 +00:00
echo ( " U " );
if ( $debug ) { echo ( " $query " . mysql_affected_rows () . " updated " ); }
}
}
2010-06-17 10:46:04 +00:00
$valid [ $type ][ $index ] = 1 ;
2010-06-09 20:03:16 +00:00
return $return ;
}
2010-06-17 14:26:30 +00:00
function discover_toner ( & $valid , $device , $oid , $index , $type , $descr , $capacity = NULL , $current = NULL )
2010-03-11 19:09:19 +00:00
{
global $config , $debug ;
if ( $debug ) { echo ( " $oid , $index , $type , $descr , $capacity\n " ); }
2010-02-15 05:07:18 +00:00
2010-03-11 19:09:19 +00:00
if ( mysql_result ( mysql_query ( " SELECT count(toner_id) FROM `toner` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND toner_type = ' $type ' AND `toner_index` = ' $index ' " ), 0 ) == '0' )
{
$query = " INSERT INTO toner (`device_id`, `toner_oid`, `toner_index`, `toner_type`, `toner_descr`, `toner_capacity`, `toner_current`) " ;
$query .= " VALUES (' " . $device [ 'device_id' ] . " ', ' $oid ', ' $index ', ' $type ', ' $descr ', ' $capacity ', ' $current ') " ;
mysql_query ( $query );
echo ( " + " );
}
else
{
$toner_entry = mysql_fetch_array ( mysql_query ( " SELECT * FROM `toner` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND toner_type = ' $type ' AND `toner_index` = ' $index ' " ));
if ( $oid == $toner_entry [ 'toner_oid' ] && $descr == $toner_entry [ 'toner_descr' ] && $capacity == $toner_entry [ 'toner_capacity' ])
{
echo ( " . " );
}
else
{
2010-04-17 19:35:48 +00:00
mysql_query ( " UPDATE toner SET `toner_descr` = ' $descr ', `toner_oid` = ' $oid ', `toner_capacity` = ' $capacity ' WHERE `device_id` = ' " . $device [ 'device_id' ] . " ' AND toner_type = ' $type ' AND `toner_index` = ' $index ' " );
2010-03-11 19:09:19 +00:00
echo ( " U " );
}
}
2010-06-17 14:26:30 +00:00
$valid [ $type ][ $index ] = 1 ;
2010-03-11 19:09:19 +00:00
return $return ;
}
2010-02-15 01:26:50 +00:00
?>