Example #1
0
 public function podOn($ip_address = "172.20.16.5", $podname = "Dhading")
 {
     date_default_timezone_set('Asia/Kathmandu');
     $apiPod = ApiPod::where('pod', '=', $podname)->first();
     if (is_object($apiPod)) {
         $apiPod_array = $apiPod->toArray();
         $pod = Pod::where('pod_api_id', '=', $apiPod_array['id'])->first();
         if (is_object($pod)) {
             $pod_array = $pod->toArray();
             $down = OffPod::where('pod_id', '=', $pod_array['id'])->first();
             if (is_object($down)) {
                 $down->delete();
                 $downPod = $down->toArray();
                 //insert into pod logs
                 $downPodLog = array();
                 $downPodLog['pod_id'] = $downPod['pod_id'];
                 $downPodLog['from_time'] = $downPod['created_at'];
                 $downPodLog['to_time'] = date('Y-m-d H:i:s');
                 $downPodLog['state'] = $downPod['state'];
                 if ($downPod['schedule_id'] != 0) {
                     $downPodLog['schedule_from_time'] = $down->schedule->from_time;
                     $downPodLog['schedule_to_time'] = $down->schedule->to_time;
                 }
                 $offPodLog = OffPodLog::create($downPodLog);
                 if ($downPod['state'] == '3') {
                     $this->sendNotification($param = array('type' => 'on', 'pod_id' => $pod_array['id'], 'description' => $apiPod_array['pod'] . " which was in red zone is on "));
                 } elseif ($downPod['state'] == '2') {
                     $this->sendNotification($param = array('type' => 'on', 'pod_id' => $pod_array['id'], 'description' => $apiPod_array['pod'] . " which was in yellow zone is on "));
                 } elseif ($downPod['state'] == '1' or $downPod['state'] == '0') {
                     $this->sendNotification($param = array('type' => 'on', 'pod_id' => $pod_array['id'], 'description' => $apiPod_array['pod'] . " which was in blue zone is on "));
                 }
             }
         }
     }
 }