More updates

This commit is contained in:
laf
2015-08-17 14:31:21 +00:00
parent dc05958a12
commit 62f88a4ec4
3 changed files with 37 additions and 11 deletions
+6
View File
@@ -1238,3 +1238,9 @@ function fping($host,$params) {
function function_check($function) {
return function_exists($function);
}
function force_influx_data($type,$data) {
if ($type == 'f' || $type == 'float') {
return(sprintf("%.1f",$data));
}
}// end force_influx_data
+1 -2
View File
@@ -75,8 +75,7 @@ if (is_numeric($uptime)) {
}
$measurement = 'uptime';
echo "BOOM " . sprintf("%.1f",$uptime) . " YAH\n";
$fields = array('uptime' => $uptime);
$fields = array('uptime' => force_influx_data('f',$uptime));
influx_update($device,$measurement,$tags,$fields);
rrdtool_update($uptime_rrd, 'N:'.$uptime);
+30 -9
View File
@@ -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) {
$tmp_fields = array();
$tmp_tags[] = "host=".$device['hostname'];
$tmp_tags[] = "hostname=".$device['hostname'];
foreach ($tags as $k => $v) {
$tmp_tags[] = "$k=$v";
}
@@ -317,13 +342,9 @@ function influx_update($device,$measurement,$tags=array(),$fields) {
$tags = implode(',', $tmp_tags);
$fields = implode(',', $tmp_fields);
$influx_url = 'http://localhost:8086/write?db=librenms';
$influx_conn = influx_connect();
$ch = curl_init($influx_url);
$post = "$measurement,$tags $fields";
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
echo "YEAH $response END\n";
$data = "$measurement,$tags $fields";
$response = influx_write($influx_conn,$data);
d_echo($response);
}
}// end influx_update