public function action_edit() { if ($_POST) { $val = \Validation::forge(); $val->add_field('type', 'Action', 'required|min_length[1]|max_length[20]'); $val->add_field('url', 'Value', 'required|min_length[1]'); $val->add_field('usr', 'Value', 'max_length[200]'); $val->add_field('pwd', 'Value', 'max_length[200]'); if ($val->run()) { $nagios = new \Nagios($val->validated('url')); $nagios->auth($val->validated('usr'), $val->validated('pwd')); $code = $nagios->testConnection(); if ($code == 200) { $monitor = Model_Source::find()->where('content', $val->validated('url'))->where('meta_update_user', $this->user)->get_one(); if ($monitor) { //$monitor->'typeID'=>$val->validated('type'); $monitor->user = $val->validated('usr'); $monitor->pass = $val->validated('pwd'); $monitor->content = $val->validated('url'); $monitor->meta_update_time = time(); //'meta_update_user'=>$this->user //); //$source=new Model_Monitoring_Source($q); $monitor->save(); $code = 'ok'; } else { $code = 'no'; } } echo json_encode(array('code' => $code, 'data' => array('name' => 'Nagios', 'content' => $val->validated('url')))); } } }
public function action_index() { $elements = array(); $total = array('hostTotals' => 0, 'hostTotalsUP' => 0, 'hostTotalsDOWN' => 0, 'hostTotalsCRITICAL' => 0, 'hostTotalsUNREACHABLE' => 0, 'hostTotalsPROBLEMS' => 0, 'serviceTotals' => 0, 'serviceTotalsOK' => 0, 'serviceTotalsWARNING' => 0, 'serviceTotalsCRITICAL' => 0, 'serviceTotalsUNKNOWN' => 0, 'serviceTotalsPROBLEMS' => 0, 'serviceTotals' => 0, 'nagiosCode' => array()); $sources = Model_Source::find()->where('meta_update_user', $this->user)->get(); foreach ($sources as $source) { $nagios = new \Nagios($source->content); $nagios->auth($source->user, $source->pass); $data = $nagios->getData($total); $elements = array_merge($elements, $data[0]); $total = $data[1]; } echo json_encode(array('total' => $total, 'services' => $elements)); }