protected function check()
    {
        try {
            $options = $this->getOptions();

            // retrieve player count
            $response = $this->mcStatus->query(true);

            if (!is_array($response)
                || !array_key_exists('player_count', $response)
            ) {
                $this->setMessage('No response from Minecraft server query.');
                $this->setCode(self::STATE_UNKNOWN);

                return $this;
            }

            $playerCount = $response['player_count'];

            if ($playerCount >= (int)$options['thresholdCritical']) {
                $this->setMessage(
                    sprintf(
                        'CRITICAL - %1$u players currently logged in|users=%1$u',
                        $response['player_count']
                    )
                );
                $this->setCode(self::STATE_CRITICAL);

                return $this;
            }

            if ($playerCount >= (int)$options['thresholdWarning']) {
                $this->setMessage(
                    sprintf(
                        'WARNING - %u players currently logged in|users=%1$u',
                        $response['player_count']
                    )
                );
                $this->setCode(self::STATE_WARNING);

                return $this;
            }

            $this->setMessage(
                sprintf(
                    'OK - %u players currently logged in|users=%1$u',
                    $playerCount
                )
            );
            $this->setCode(self::STATE_OK);

            return $this;

        } catch (\Exception $e) {
            $this->setMessage('Error from Mcstat: ' . $e->getMessage());
            $this->setCode(self::STATE_UNKNOWN);

            return $this;
        }
    }
protected function check()
    {
        try {
            $options = $this->getOptions();

            // retrieve player count
            $response = $this->mcStatus->query(true);

            if (!is_array($response)
                || !array_key_exists('player_count', $response)
            ) {
                $this->setMessage('No response from Minecraft server query.');
                $this->setCode(self::STATE_UNKNOWN);

                return $this;
            }

            $playerCount = $response['player_count'];

            if ($playerCount >= (int)$options['thresholdCritical']) {
                $this->setMessage(
                    sprintf(
                        'CRITICAL - %1$u players currently logged in|users=%1$u',
                        $response['player_count']
                    )
                );
                $this->setCode(self::STATE_CRITICAL);

                return $this;
            }

            if ($playerCount >= (int)$options['thresholdWarning']) {
                $this->setMessage(
                    sprintf(
                        'WARNING - %u players currently logged in|users=%1$u',
                        $response['player_count']
                    )
                );
                $this->setCode(self::STATE_WARNING);

                return $this;
            }

            $this->setMessage(
                sprintf(
                    'OK - %u players currently logged in|users=%1$u',
                    $playerCount
                )
            );
            $this->setCode(self::STATE_OK);

            return $this;

        } catch (\Exception $e) {
            $this->setMessage('Error from Mcstat: ' . $e->getMessage());
            $this->setCode(self::STATE_UNKNOWN);

            return $this;
        }
    }
protected function check ( ) { try { $ options = $ this -> getOptions ( ) ; // retrieve player count $ response = $ this -> mcStatus -> query ( true ) ; if ( ! is_array ( $ response ) || ! array_key_exists ( 'player_count' , $ response ) ) { $ this -> setMessage ( 'No response from Minecraft server query.' ) ; $ this -> setCode ( self :: STATE_UNKNOWN ) ; return $ this ; } $ playerCount = $ response [ 'player_count' ] ; if ( $ playerCount >= ( int ) $ options [ 'thresholdCritical' ] ) { $ this -> setMessage ( sprintf ( 'CRITICAL - %1$u players currently logged in|users=%1$u' , $ response [ 'player_count' ] ) ) ; $ this -> setCode ( self :: STATE_CRITICAL ) ; return $ this ; } if ( $ playerCount >= ( int ) $ options [ 'thresholdWarning' ] ) { $ this -> setMessage ( sprintf ( 'WARNING - %u players currently logged in|users=%1$u' , $ response [ 'player_count' ] ) ) ; $ this -> setCode ( self :: STATE_WARNING ) ; return $ this ; } $ this -> setMessage ( sprintf ( 'OK - %u players currently logged in|users=%1$u' , $ playerCount ) ) ; $ this -> setCode ( self :: STATE_OK ) ; return $ this ; } catch ( \ Exception $ e ) { $ this -> setMessage ( 'Error from Mcstat: ' . $ e -> getMessage ( ) ) ; $ this -> setCode ( self :: STATE_UNKNOWN ) ; return $ this ; } }
Check the amount of players on the Minecraft server.

@see Base::check()

@return $this
Check the amount of players on the Minecraft server .