diff --git a/csv/control.zaf b/csv/control.zaf new file mode 100644 index 0000000..bc9c39e --- /dev/null +++ b/csv/control.zaf @@ -0,0 +1,49 @@ + +Plugin: csv + +Description:: + CSV file reader and parser for Zabbix + It supports reading CSV and getting its data as Zabbix items + Even more it supports discovery based on CSV +:: + +Version: 0.1 + +Url: https://raw.githubusercontent.com/limosek/zaf-plugins/master/csv +Web: https://github.com/limosek/zaf-plugins/ + +# Maintainer +Maintainer: Lukas Macura + +# Dependencies +Depends-dpkg: dash php-cli +Depends-opkg: busybox php + +Install-bin: get_fields.php get_rows.php +Install-files: functions.inc.php + +Item discovery.fields: +Parameters:: + csv '' '' + columns '1-100' '' + delimiter ',' '' +:: +Description:: + Returns json field names from csv (header line) +:: +Cmd:: get_fields.php +/Item + +Item discovery.rows: +Parameters:: + csv '' '' + columns '1-100' '' + header 1 '' + delimiter ',' '' +:: +Description:: + Returns rows from CSV as autodiscovery json. +:: +Cmd:: get_rows.php +/Item + diff --git a/csv/functions.inc.php b/csv/functions.inc.php new file mode 100644 index 0000000..bb8c5d6 --- /dev/null +++ b/csv/functions.inc.php @@ -0,0 +1,51 @@ +1) { + for ($i=$range[0];$i<=$range[1];$i++) { + $columns[]=$i; + } + } else { + $columns[]=$group; + } + } + return($columns); +} + +function json_init() { + echo '{ "data":'."\n".' [ '."\n"; +} + +function json_row() { + echo "{"; +} + +function json_row_end($last=false) { + if ($last) { + echo " }\n"; + } else { + echo " },\n"; + } +} + +function json_column($name,$value,$last=false) { + echo sprintf('"{#%s}":"%s"',$name,$value); + if (!$last) echo ","; +} + +function json_end() { + echo ' ] }'."\n"; +} + diff --git a/csv/get_fields.php b/csv/get_fields.php new file mode 100644 index 0000000..c471b94 --- /dev/null +++ b/csv/get_fields.php @@ -0,0 +1,27 @@ +#!/usr/bin/php +$column) { + if (!array_key_exists($num,$range)) continue; + json_row(); + json_column("FIELD","$column",true); + json_row_end($last==$column); +} + +json_end(); + + diff --git a/csv/get_rows.php b/csv/get_rows.php new file mode 100644 index 0000000..1abb24b --- /dev/null +++ b/csv/get_rows.php @@ -0,0 +1,42 @@ +#!/usr/bin/php +