| 
									
										
										
										
											2024-10-19 13:09:16 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-26 14:22:27 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2024-11-29 16:08:56 +00:00
										 |  |  |  * Jilo components status checks | 
					
						
							| 
									
										
										
										
											2024-11-26 14:22:27 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This page ("status") checks the status of various Jilo platform components | 
					
						
							|  |  |  |  * by fetching data from agents and determining their availability. | 
					
						
							|  |  |  |  * It generates output for each platform and agent. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-10-19 13:09:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-17 08:24:50 +00:00
										 |  |  | // Get any new feedback messages
 | 
					
						
							| 
									
										
										
										
											2025-02-17 14:50:57 +00:00
										 |  |  | include '../app/helpers/feedback.php'; | 
					
						
							| 
									
										
										
										
											2025-01-13 08:45:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-22 15:03:34 +00:00
										 |  |  | require '../app/classes/agent.php'; | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  | require '../app/classes/host.php'; | 
					
						
							| 
									
										
										
										
											2024-10-22 15:03:34 +00:00
										 |  |  | $agentObject = new Agent($dbWeb); | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  | $hostObject = new Host($dbWeb); | 
					
						
							| 
									
										
										
										
											2024-10-22 15:03:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-19 13:09:16 +00:00
										 |  |  | include '../app/templates/status-server.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-26 14:22:27 +00:00
										 |  |  | // loop through all platforms to check their agents
 | 
					
						
							| 
									
										
										
										
											2024-10-22 15:03:34 +00:00
										 |  |  | foreach ($platformsAll as $platform) { | 
					
						
							| 
									
										
										
										
											2024-10-23 10:06:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-04 14:18:15 +00:00
										 |  |  |     // check if we can connect to the jilo database
 | 
					
						
							|  |  |  |     $response = connectDB($config, 'jilo', $platform['jilo_database'], $platform['id']); | 
					
						
							|  |  |  |     if ($response['error'] !== null) { | 
					
						
							| 
									
										
										
										
											2025-01-17 14:08:37 +00:00
										 |  |  |         $jilo_database_status = $response['error']; | 
					
						
							| 
									
										
										
										
											2024-12-04 14:18:15 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  |         $jilo_database_status = 'Connected'; | 
					
						
							| 
									
										
										
										
											2024-12-04 14:18:15 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-22 15:03:34 +00:00
										 |  |  |     include '../app/templates/status-platform.php'; | 
					
						
							| 
									
										
										
										
											2024-10-23 10:06:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  |     // fetch hosts for the current platform
 | 
					
						
							|  |  |  |     $hostDetails = $hostObject->getHostDetails($platform['id']); | 
					
						
							|  |  |  |     foreach ($hostDetails as $host) { | 
					
						
							|  |  |  |         // fetch agent details for the current host
 | 
					
						
							|  |  |  |         $agentDetails = $agentObject->getAgentDetails($host['id']); | 
					
						
							|  |  |  |         foreach ($agentDetails as $agent) { | 
					
						
							|  |  |  |             // we try to parse the URL to scheme:/host:port
 | 
					
						
							|  |  |  |             $agent_url = parse_url($agent['url']); | 
					
						
							|  |  |  |             $agent_protocol = isset($agent_url['scheme']) ? $agent_url['scheme']: ''; | 
					
						
							|  |  |  |             // on failure we keep the full value for displaying purpose
 | 
					
						
							|  |  |  |             $agent_host = isset($agent_url['host']) ? $agent_url['host']: $agent['url']; | 
					
						
							|  |  |  |             $agent_port = isset($agent_url['port']) ? $agent_url['port']: ''; | 
					
						
							| 
									
										
										
										
											2024-10-23 10:06:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  |             // we get agent data to check availability
 | 
					
						
							|  |  |  |             $agent_response = $agentObject->fetchAgent($agent['id'], true); | 
					
						
							|  |  |  |             $agent_data = json_decode($agent_response); | 
					
						
							| 
									
										
										
										
											2024-10-23 10:06:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  |             // determine agent availability based on response data
 | 
					
						
							|  |  |  |             if (json_last_error() === JSON_ERROR_NONE) { | 
					
						
							|  |  |  |                 $agent_availability = 'unknown'; | 
					
						
							|  |  |  |                 foreach ($agent_data as $key => $value) { | 
					
						
							|  |  |  |                     if ($key === 'error') { | 
					
						
							|  |  |  |                         $agent_availability = $value; | 
					
						
							| 
									
										
										
										
											2024-10-23 10:06:59 +00:00
										 |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  |                     if (preg_match('/_state$/', $key)) { | 
					
						
							|  |  |  |                         if ($value === 'error') { | 
					
						
							|  |  |  |                             $agent_availability = 'not running'; | 
					
						
							|  |  |  |                             break; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         if ($value === 'running') { | 
					
						
							|  |  |  |                             $agent_availability = 'running'; | 
					
						
							|  |  |  |                             break; | 
					
						
							|  |  |  |                         } | 
					
						
							| 
									
										
										
										
											2024-10-23 10:06:59 +00:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 $agent_availability = 'json error'; | 
					
						
							| 
									
										
										
										
											2024-10-23 10:06:59 +00:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  |             include '../app/templates/status-agent.php'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-10-22 15:03:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  |     echo "\n\t\t\t\t\t\t\t</div>\n"; | 
					
						
							| 
									
										
										
										
											2024-10-22 15:03:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2025-01-24 09:48:37 +00:00
										 |  |  | echo "\n\t\t\t\t\t\t</div>"; | 
					
						
							|  |  |  | echo "\n\t\t\t\t\t</div>"; | 
					
						
							|  |  |  | echo "\n\t\t\t\t</div>"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-19 13:09:16 +00:00
										 |  |  | ?>
 |