Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * @ Pirate-Sky Crew :: PHP Decoder v2
- * @ Author: pLa$71k
- * @ Web: http://pirate-sky.com
- * @ Pirate-Sky Crew © 2008 - 2013
- */
- require_once( MAINDIR."includes".DS."libs".DS."phpquery".DS."phpQuery.php" );
- class Nagios extends HostingModule
- {
- protected $modname = "Nagios monitoring module";
- protected $description = "Use with dedicated servers manager plugin to monitor services";
- protected $version = "1.0";
- protected $serverFields = array
- (
- "ssl" => false,
- "nameservers" => false,
- "maxaccounts" => false,
- "status_url" => false,
- "ip" => false,
- "hostname" => true,
- "field1" => false,
- "field2" => false
- );
- protected $serverFieldsDescription = array
- (
- "hostname" => "Nagios URL"
- );
- private $url = NULL;
- private $username = NULL;
- private $password = NULL;
- private static $columns = array
- (
- 1 => "service",
- 2 => "status",
- 3 => "lastcheck",
- 4 => "duration",
- 5 => "attempt",
- 6 => "info"
- );
- private static $severity = array
- (
- "OK" => 1,
- "WARNING" => 2,
- "UNKNOWN" => 3,
- "CRITICAL" => 4
- );
- public function connect( $connect )
- {
- if ( !preg_match( "/http[s]?:/", $connect['host'] ) )
- {
- $connect['host'] = "http://".$connect['host'];
- }
- if ( stripos( $connect['host'], ".cgi" ) !== false )
- {
- $connect['host'] = substr( $connect['host'], 0, strrpos( $connect['host'], "/" ) );
- }
- $connect['host'] = rtrim( $connect['host'], "/" );
- $this->url = $connect['host']."/status.cgi?limit=0";
- $this->username = $connect['username'];
- $this->password = $connect['password'];
- }
- public function testConnection( )
- {
- return $this->loadStatuses( );
- }
- public function Create( )
- {
- return true;
- }
- public function loadStatuses( )
- {
- $curl = curl_init( );
- curl_setopt( $curl, CURLOPT_URL, $this->url );
- curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $curl, CURLOPT_TIMEOUT, 30 );
- curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
- curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false );
- curl_setopt( $curl, CURLOPT_USERPWD, $this->username.":".$this->password );
- $out = curl_exec( $curl );
- if ( $out === false )
- {
- $this->addError( ucwords( curl_error( $curl ) ) );
- }
- $dom = phpQuery::newdocument( $out, "text/html" );
- $return = array( );
- if ( !phpQuery::pq( "table.status" ) )
- {
- $this->addError( "Unable to parse nagios response, check login details" );
- return false;
- }
- $trs = phpQuery::pq( "table.status", $dom )->children( "tr" )->next( );
- $hostname = "";
- $i = $j = 0;
- foreach ( $trs as $row )
- {
- $tds = pq( $row )->children( );
- foreach ( $tds as $td )
- {
- $td = pq( $td );
- $t = trim( $col = $td->text( ) );
- if ( !$i )
- {
- if ( $t )
- {
- $hostname = $t;
- $j = 0;
- }
- }
- else
- {
- $return[$hostname]['services'][$j][self::$columns[$i]] = $t;
- }
- ++$i;
- $last = $return[$hostname]['services'][$j]['status'];
- }
- if ( !$return[$hostname]['status'] )
- {
- $return[$hostname]['status'] = $last;
- }
- if ( self::$severity[$return[$hostname]['status']] < self::$severity[$last] )
- {
- $return[$hostname]['status'] = $last;
- }
- $i = 0;
- ++$j;
- }
- return $return;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement