root / plugins / rackspace / rackspace_cdn_count.php @ 430d68ff
Historique | Voir | Annoter | Télécharger (1,77 ko)
| 1 | b354f281 | Andrey Kozhokaru | #!/usr/bin/php
|
|---|---|---|---|
| 2 | # Author Andrey Kozhokaru <andrey@kozhokaru.com>
|
||
| 3 | # Plugin to monitor Rackspace File count
|
||
| 4 | #
|
||
| 5 | # Parameters:
|
||
| 6 | #
|
||
| 7 | # config (required)
|
||
| 8 | #
|
||
| 9 | #
|
||
| 10 | #%# family=manual
|
||
| 11 | |||
| 12 | |||
| 13 | <?php |
||
| 14 | $x_auth_user='###NAME'; |
||
| 15 | $x_auth_key='###KEY'; |
||
| 16 | $api_url='https://auth.api.rackspacecloud.com/v1.0/'; |
||
| 17 | |||
| 18 | function SplitTwice($content,$first,$second) { |
||
| 19 | $s1=split($first,$content); |
||
| 20 | $splitted=split($second,$s1[1]); |
||
| 21 | return trim($splitted[0]); |
||
| 22 | } |
||
| 23 | |||
| 24 | |||
| 25 | if ($argv[1]=='config'){ |
||
| 26 | print "graph_title Rackspace CDN files count\n"; |
||
| 27 | print "graph_vlabel Files Count\n"; |
||
| 28 | print "graph_category rackspace\n"; |
||
| 29 | print "count.label files count\n"; |
||
| 30 | print "graph_args --base 1000\n"; |
||
| 31 | |||
| 32 | exit;
|
||
| 33 | } |
||
| 34 | |||
| 35 | $header_auth = array("X-Auth-User:$x_auth_user","X-Auth-Key:$x_auth_key"); |
||
| 36 | |||
| 37 | //Authentication
|
||
| 38 | $ch = curl_init();
|
||
| 39 | curl_setopt($ch, CURLOPT_URL, $api_url); |
||
| 40 | curl_setopt($ch, CURLOPT_HEADER, true); |
||
| 41 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header_auth); |
||
| 42 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
| 43 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
||
| 44 | $data = curl_exec($ch); |
||
| 45 | curl_close($ch);
|
||
| 46 | |||
| 47 | |||
| 48 | $cdn_url= SplitTwice($data,'X-Storage-Url: ','Cache'); |
||
| 49 | $token= SplitTwice ($data,'X-Auth-Token:','X-Storage-Token:'); |
||
| 50 | |||
| 51 | |||
| 52 | $header_cdn = array ("X-Auth-Token:$token"); |
||
| 53 | |||
| 54 | |||
| 55 | //Get data
|
||
| 56 | $ch1 = curl_init();
|
||
| 57 | curl_setopt($ch1, CURLOPT_URL, $cdn_url); |
||
| 58 | curl_setopt($ch1, CURLOPT_HEADER, true); |
||
| 59 | curl_setopt($ch1, CURLOPT_HTTPHEADER, $header_cdn); |
||
| 60 | curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); |
||
| 61 | curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, 30); |
||
| 62 | $data1 = curl_exec($ch1); |
||
| 63 | curl_close($ch1);
|
||
| 64 | |||
| 65 | $objects_count = SplitTwice($data1,'X-Account-Object-Count:','X-Account-Bytes-Used:'); |
||
| 66 | $objects_bytes_used = SplitTwice ($data1,'X-Account-Bytes-Used:','X-Account-Container-Count:'); |
||
| 67 | |||
| 68 | echo 'count.value '.$objects_count; |
||
| 69 | |||
| 70 | ?> |
