1) { for ($i=1 ; $i array('method' => "POST", 'header' => $header, 'content' => $request))); $file = file_get_contents("http://$host/$url", false, $context); if (!$file) { die("+ No response\n"); } if (in_array('Content-Encoding: deflate', $http_response_header)) { $lenc=strlen($file); echo "+ Compressed response : $lenc\n"; $file = gzuncompress($file); $lend=strlen($file); echo "+ Uncompressed response : $lend (".round(100.0*$lenc/$lend)."%)\n"; } $response = xmlrpc_decode($file); if (!is_array($response)) { echo $file; die ("+ Bad response\n"); } if (xmlrpc_is_fault($response)) { echo("xmlrpc error(".$response['faultCode']."): ".$response['faultString']."\n"); } else { return $response; } } if (!extension_loaded("xmlrpc")) { die("Extension xmlrpc not loaded\n"); } # What state is the HOST in? switch ($event) { case "UP": # The host just came back up - perhaps we should close the ticket... if ($lasthostproblemid != 0) { $arg['method'] = "glpi.doLogin"; $arg['url'] = $xmlurl; $arg['host'] = $xmlhost; $arg['login_password'] = $password; $arg['login_name'] = $user; $response = call_glpi($arg); $session = $response['session']; unset($arg); unset($response); if (!empty($session)){ $arg['method'] = "glpi.listTickets"; $arg['url'] = $xmlurl; $arg['host'] = $xmlhost; $arg['session'] = $session; $arg['order'] = "id"; $arg['status'] = '1'; $response = call_glpi($arg); unset($arg); foreach ($response as $ticket) { if ($ticket['name'] == "$eventhost is down!") { $fields = array ('Ticket' => array (array ('id' => $ticket['id'], 'status' => '6'))); $arg['method'] = "glpi.updateObjects"; $arg['url'] = $xmlurl; $arg['host'] = $xmlhost; $arg['session'] = $session; $arg['fields'] = $fields; $response = call_glpi($arg); unset($arg); unset($response); } } } $arg['method'] = "glpi.doLogout"; $arg['url'] = $xmlurl; $arg['host'] = $xmlhost; $arg['session'] = $session; $response = call_glpi($arg); unset($arg); unset($response); } break; //case "UNREACHABLE": # We don't really care about warning states, since the host is probably still running... case "DOWN": # Aha! The host appears to have a problem - perhaps we should open a ticket... # Is this a "soft" or a "hard" state? switch ($state) { # We're in a "soft" state, meaning that Nagios is in the middle of retrying the # check before it turns into a "hard" state and contacts get notified... //case "SOFT": # We don't want to open a ticket on a "soft" state. case "HARD": if ($lasthostproblemid != 1) { if ($hostattempts == $maxhostattempts){ $arg['method'] = "glpi.doLogin"; $arg['url'] = $xmlurl; $arg['host'] = $xmlhost; $arg['login_password'] = $password; $arg['login_name'] = $user; $response = call_glpi($arg); $session = $response['session']; unset($arg); unset($response); if (!empty($session)) { $title = "$eventhost is down!"; $content = "$eventhost is down. Please check that the server is up and responding"; $arg['method'] = "glpi.createTicket"; $arg['url'] = $xmlurl; $arg['host'] = $xmlhost; $arg['session'] = $session; $arg['title'] = $title; $arg['content'] = $content; $arg['urgancy'] = 5; $arg['use_email_notification'] = 1; $response = call_glpi($arg); unset($arg); unset($response); } $arg['method'] = "glpi.doLogout"; $arg['url'] = $xmlurl; $arg['host'] = $xmlhost; $arg['session'] = $session; $response = call_glpi($arg); unset($arg); unset($response); } } //end state cases } //end event cases } ?>