cPanel Bandwidth Checking Script
I've been pretty frustrated with the way that cPanel notifies (or doesn't notify) me of bandwidth overages. Seems sometimes I get them and sometimes not. So when I found out that you can do this with the WHM XML api I wanted to get it set up ASAP. This script can be used along with cron and PHPMailer to notify you of the bandwidth usage for all your domains in WHM. I have mine set up to notify me daily so I can keep track of my bandwidth usage.
To get your Access key for WHM, login and select Setup Remote Access Key.
If you need more help with the WHM XML API, you can find it here. You can download PHPMailer here.
Bandwidth "; foreach ($user as $v) { $query = "https://".$v[2].":2087/xml-api/showbw"; $curl = curl_init(); # Create Curl Object curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0); # Allow certs that do not match the domain curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0); # Allow self-signed certs curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); # Return contents of transfer on curl_exec $header[0] = "Authorization: WHM $v[0]:" . preg_replace("'(\r|\n)'","",$v[1]); # Remove newlines from the hash curl_setopt($curl,CURLOPT_HTTPHEADER,$header); # Set curl header curl_setopt($curl, CURLOPT_URL, $query); # Set your URL $result = curl_exec($curl); # Execute Query, assign to $result if ($result == false) { error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query"); } curl_close($curl); $xml = new SimpleXMLElement($result); $output .= "".$v[2]."
"; $output .= "
Domain | '; $output .= 'Limit | '; $output .= 'Percent | '; $output .= '|
---|---|---|---|
' . $acct->maindomain . ' | '; $output .= '' . $mbs . 'MB | '; $output .= '' . $percent . '% | '; $output .= '
|
';
$output .= '