1<?php defined('SYSPATH') OR die('No direct access allowed.'); 2/** 3 * Xport controller. 4 * 5 * @package pnp4nagios 6 * @author Joerg Linge 7 * @license GPL 8 */ 9class Xport_Controller extends System_Controller { 10 11 public function __construct() 12 { 13 parent::__construct(); 14 // Disable auto-rendering 15 $this->auto_render = FALSE; 16 $this->data->getTimeRange($this->start,$this->end,$this->view); 17 18 } 19 20 public function xml(){ 21 if(isset($this->host) && isset($this->service)){ 22 $this->data->buildXport($this->host,$this->service); 23 if($this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']) === FALSE){ 24 header('Content-Type: application/xml'); 25 print "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; 26 print "<NAGIOS>\n"; 27 print "<ERROR>not authorized</ERROR>\n"; 28 print "</NAGIOS>\n"; 29 exit; 30 } 31 $data = $this->rrdtool->doXport($this->data->XPORT); 32 header('Content-Type: application/xml'); 33 print $data; 34 }else{ 35 throw new Kohana_Exception('error.xport-host-service'); 36 } 37 } 38 39 public function json(){ 40 if(isset($this->host) && isset($this->service)){ 41 $this->data->buildXport($this->host,$this->service); 42 if($this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']) === FALSE){ 43 header('Content-type: application/json'); 44 print json_encode("not authorized"); 45 exit; 46 } 47 $data = $this->rrdtool->doXport($this->data->XPORT); 48 $json = json_encode(simplexml_load_string($data)); 49 header('Content-type: application/json'); 50 print $json; 51 }else{ 52 throw new Kohana_Exception('error.xport-host-service'); 53 } 54 } 55 56 public function csv(){ 57 if(isset($this->host) && isset($this->service)){ 58 $this->data->buildXport($this->host,$this->service); 59 if($this->auth->is_authorized($this->data->MACRO['AUTH_HOSTNAME'], $this->data->MACRO['AUTH_SERVICEDESC']) === FALSE){ 60 header("Content-Type: text/plain; charset=UTF-8"); 61 print "not authorized"; 62 exit; 63 } 64 $data = $this->rrdtool->doXport($this->data->XPORT); 65 $csv = $this->data->xml2csv($data); 66 header("Content-Type: text/plain; charset=UTF-8"); 67 print $csv; 68 }else{ 69 throw new Kohana_Exception('error.xport-host-service'); 70 } 71 } 72 73 74} 75