mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-01 08:03:30 +02:00
More updates
This commit is contained in:
@@ -1238,3 +1238,9 @@ function fping($host,$params) {
|
|||||||
function function_check($function) {
|
function function_check($function) {
|
||||||
return function_exists($function);
|
return function_exists($function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function force_influx_data($type,$data) {
|
||||||
|
if ($type == 'f' || $type == 'float') {
|
||||||
|
return(sprintf("%.1f",$data));
|
||||||
|
}
|
||||||
|
}// end force_influx_data
|
||||||
|
|||||||
@@ -75,8 +75,7 @@ if (is_numeric($uptime)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$measurement = 'uptime';
|
$measurement = 'uptime';
|
||||||
echo "BOOM " . sprintf("%.1f",$uptime) . " YAH\n";
|
$fields = array('uptime' => force_influx_data('f',$uptime));
|
||||||
$fields = array('uptime' => $uptime);
|
|
||||||
influx_update($device,$measurement,$tags,$fields);
|
influx_update($device,$measurement,$tags,$fields);
|
||||||
|
|
||||||
rrdtool_update($uptime_rrd, 'N:'.$uptime);
|
rrdtool_update($uptime_rrd, 'N:'.$uptime);
|
||||||
|
|||||||
@@ -304,9 +304,34 @@ function rrdtool_escape($string, $maxlength=null){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function influx_connect() {
|
||||||
|
global $config;
|
||||||
|
if ($config['influxdb']['transport'] == 'http') {
|
||||||
|
|
||||||
|
$influx_url = $config['influxdb']['url'] . '/write?db=' . $config['influxdb']['db'];
|
||||||
|
|
||||||
|
$ch = curl_init($influx_url);
|
||||||
|
|
||||||
|
if (!empty($config['influxdb']['username']) && !empty($config['influxdb']['password'])) {
|
||||||
|
curl_setopt($ch, CURLOPT_USERPWD, $config['influxdb']['username'] . ":" . $config['influxdb']['password']);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
|
}
|
||||||
|
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
|
||||||
|
return($ch);
|
||||||
|
}
|
||||||
|
}// end influx_connect
|
||||||
|
|
||||||
|
function influx_write($ch,$data) {
|
||||||
|
global $config;
|
||||||
|
if ($config['influxdb']['transport'] == 'http') {
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||||
|
return(curl_exec($ch));
|
||||||
|
}
|
||||||
|
}// end influx_write
|
||||||
|
|
||||||
function influx_update($device,$measurement,$tags=array(),$fields) {
|
function influx_update($device,$measurement,$tags=array(),$fields) {
|
||||||
$tmp_fields = array();
|
$tmp_fields = array();
|
||||||
$tmp_tags[] = "host=".$device['hostname'];
|
$tmp_tags[] = "hostname=".$device['hostname'];
|
||||||
foreach ($tags as $k => $v) {
|
foreach ($tags as $k => $v) {
|
||||||
$tmp_tags[] = "$k=$v";
|
$tmp_tags[] = "$k=$v";
|
||||||
}
|
}
|
||||||
@@ -317,13 +342,9 @@ function influx_update($device,$measurement,$tags=array(),$fields) {
|
|||||||
$tags = implode(',', $tmp_tags);
|
$tags = implode(',', $tmp_tags);
|
||||||
$fields = implode(',', $tmp_fields);
|
$fields = implode(',', $tmp_fields);
|
||||||
|
|
||||||
$influx_url = 'http://localhost:8086/write?db=librenms';
|
$influx_conn = influx_connect();
|
||||||
|
|
||||||
$ch = curl_init($influx_url);
|
$data = "$measurement,$tags $fields";
|
||||||
$post = "$measurement,$tags $fields";
|
$response = influx_write($influx_conn,$data);
|
||||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
|
||||||
$response = curl_exec($ch);
|
|
||||||
echo "YEAH $response END\n";
|
|
||||||
d_echo($response);
|
d_echo($response);
|
||||||
}
|
}// end influx_update
|
||||||
|
|||||||
Reference in New Issue
Block a user