コード例 #1
0
ファイル: influxdb.inc.php プロジェクト: nguillaumin/librenms
function influx_update($device, $measurement, $tags = array(), $fields)
{
    global $influxdb, $config, $console_color;
    if ($influxdb !== false) {
        $tmp_fields = array();
        $tmp_tags['hostname'] = $device['hostname'];
        foreach ($tags as $k => $v) {
            $v = preg_replace(array('/ /', '/,/', '/=/'), array('\\ ', '\\,', '\\='), $v);
            if (empty($v)) {
                $v = '_blank_';
            }
            $tmp_tags[$k] = $v;
        }
        foreach ($fields as $k => $v) {
            $tmp_fields[$k] = force_influx_data('f', $v);
        }
        d_echo("\nInfluxDB data:\n");
        d_echo($measurement);
        d_echo($tmp_tags);
        d_echo($tmp_fields);
        d_echo("\nEND\n");
        if ($config['noinfluxdb'] !== true) {
            $points = array(new InfluxDB\Point($measurement, null, $tmp_tags, $tmp_fields));
            $result = $influxdb->writePoints($points);
        } else {
            print $console_color->convert('[%gInfluxDB Disabled%n] ', false);
        }
        //end if
    }
    //end if
}
コード例 #2
0
ファイル: influxdb.inc.php プロジェクト: szatam/librenms
function influx_update($device, $measurement, $tags, $fields)
{
    global $influxdb, $config;
    if ($influxdb !== false) {
        $tmp_fields = array();
        $tmp_tags['hostname'] = $device['hostname'];
        foreach ($tags as $k => $v) {
            $v = preg_replace(array('/ /', '/,/', '/=/'), array('\\ ', '\\,', '\\='), $v);
            if (empty($v)) {
                $v = '_blank_';
            }
            $tmp_tags[$k] = $v;
        }
        foreach ($fields as $k => $v) {
            $tmp_fields[$k] = force_influx_data($v);
            if ($tmp_fields[$k] === null) {
                unset($tmp_fields[$k]);
            }
        }
        d_echo("\nInfluxDB data:\n");
        d_echo($measurement);
        d_echo($tmp_tags);
        d_echo($tmp_fields);
        d_echo("\nEND\n");
        if ($config['noinfluxdb'] !== true) {
            $points = array(new InfluxDB\Point($measurement, null, $tmp_tags, $tmp_fields));
            try {
                $result = $influxdb->writePoints($points);
            } catch (Exception $e) {
                d_echo("Caught exception: " . $e->getMessage() . PHP_EOL);
                d_echo($e->getTrace());
            }
        } else {
            c_echo("[%gInfluxDB Disabled%n]\n");
        }
        //end if
    }
    //end if
}