From ba5d5b558ec39e32f527a62f76a85d834677de0b Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 10 Feb 2015 10:18:38 +0100 Subject: [PATCH] Fix disco_filesystem and switch to JSON module instead of manually printing (invalid) JSON data --- zabbix_scripts/disco_filesystems | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/zabbix_scripts/disco_filesystems b/zabbix_scripts/disco_filesystems index e8f32a6..a9722e9 100644 --- a/zabbix_scripts/disco_filesystems +++ b/zabbix_scripts/disco_filesystems @@ -1,9 +1,8 @@ #!/usr/bin/perl - -$first = 1; - -print "{\n"; -print "\t\"data\":[\n\n"; + +use JSON; +my $json; +@{$json->{data}} = (); my $cmd; my $re; @@ -36,19 +35,15 @@ for (`$cmd`){ chomp($t); $critical = $t if ($t =~ m/^\d+$/); } - $fsname =~ s!/!\\/!g; - - print "\t,\n" if not $first; - $first = 0; - - print "\t{\n"; - print "\t\t\"{#FSNAME}\":\"$fsname\",\n"; - print "\t\t\"{#FSTYPE}\":\"$fstype\"\n"; - print "\t\t\"{#FSDEVICE}\":\"$block\"\n"; - print "\t\t\"{#FSWARNTHRES}\":\"$warning\"\n"; - print "\t\t\"{#FSCRITTHRES}\":\"$critical\"\n"; - print "\t}\n"; + + push @{$json->{data}}, { + "{#FSNAME}" => $fsname, + "{#FSTYPE}" => $fstype, + "{#FSDEVICE}" => $block, + "{#FSWARNTHRES}" => $warning, + "{#FSCRITTHRES}" => $critical + }; } - -print "\n\t]\n"; -print "}\n"; + +print to_json($json); +exit(0);