#!/usr/bin/env perl use Env qw(DOCUMENT_ROOT QUERY_STRING); use strict; use warnings; my $method = 'xml'; if ( $QUERY_STRING ) { if ( $QUERY_STRING =~ /method=([a-z]+)/ ) { if ( $1 eq 'json' or $1 eq 'xml' ) { $method = $1; } } } my %mon2num = qw( jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8 sep 9 oct 10 nov 11 dec 12 ); my $json_file = (( $DOCUMENT_ROOT ) ? $DOCUMENT_ROOT : '.' ).'/correlation_graph.json'; my $json_string = ''; open IN, $json_file or die "Alert JSON file not found"; $json_string .= $_ while ( ); close IN; if ( $method eq 'json' ) { print "Content-Type: application/json\n\n"; print $json_string; } elsif ( $method eq 'xml' ) { use JSON; use Time::Local; my @json = @{JSON->new->utf8->decode ( $json_string )}; print "Content-Type: application/xml\n\n". "\n\n". "\n"; for ( @json ) { print "\t\n"; } print "\n"; }