-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_xml_response
executable file
·64 lines (50 loc) · 1.44 KB
/
check_xml_response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/php
<?php
// return code: 0 OK | 1 Warning | 2 Critical | 3 Unknown
function usage() {
echo <<<TXT
Usage: {$argv[0]} [URL] [method] [xml_file]
Example: {$argv[0]} http://example.com/callback POST request.xml
{$argv[0]} http://example.com/search.php?q=X GET
Will return success if the XML response is > 1 in length
Will return failure if server error or < 1 in length
TXT;
exit(3);
}
if (count($argv) < 3) {
usage();
}
$ch = curl_init();
$url = $argv[1];
if ($argv[2] == "POST") {
$xml = @file_get_contents($argv[3]);
if (!$xml) {
echo "Could not read file contents of {$argv[2]}\n";
exit(3);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml; charset=UTF-8',
'Content-Length: ' . strlen($xml)
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_POST, TRUE);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, FALSE);
curl_setopt($ch, CURLOPT_PROXY, '');
$response = curl_exec($ch);
$info = curl_getinfo($ch);
if ($info['http_code'] != 200) {
$curl_error = curl_error($ch);
echo "Error: HTTP code was {$info['http_code']}, response was $curl_error\n";
exit(1);
}
if (strlen($response) > 1) {
echo "OK: response was $response\n";
exit(0);
}
echo "Error: response length was less than 1\n";
exit(1);