@@ -1539,26 +1539,36 @@ public function _getLogData($log) {
15391539 }
15401540
15411541 private function _checkTcp ($ host , $ port ) {
1542-
1542+ /* Try to open a connection */
15431543 $ fp = @fsockopen ($ host , $ port , $ errno , $ errstr , 2 );
15441544
15451545 if ($ fp ) {
15461546 /*
1547- * We got a connection, but maybe apache is not able to send data over this
1548- * connection ?
1547+ * We got a connection, this means, everything is O.K.
1548+ * But maybe we are able to do more deep testing ?
15491549 */
1550- fwrite ($ fp , "GET / HTTP/1.0 \r\n\r\n" );
1551- stream_set_timeout ($ fp , 2 );
1552- $ res = fread ($ fp , 10 );
1553- $ info = stream_get_meta_data ($ fp );
1554- fclose ($ fp );
1555- if ($ info ['timed_out ' ]) {
1556- return false ; // Apache was not able to send data over this connection
1557- } else {
1558- return true ; // Apache was able to send data over this connection
1550+ if ($ port == 80 ) {
1551+ /*
1552+ * Port 80 means, testing APACHE
1553+ * So we can do a deepter test and try to get data over this connection.
1554+ * (if apache hangs, we get a connection but a timeout by trying to GET the data!)
1555+ */
1556+ fwrite ($ fp , "GET / HTTP/1.0 \r\n\r\n" );
1557+ stream_set_timeout ($ fp , 5 ); // Timeout after 5 seconds
1558+ $ res = fread ($ fp , 10 ); // try to get 10 bytes (enough to test!)
1559+ $ info = stream_get_meta_data ($ fp );
1560+ if ($ info ['timed_out ' ]) {
1561+ return false ; // Apache was not able to send data over this connection
1562+ }
15591563 }
1564+
1565+ /* The connection is no longer needed */
1566+ fclose ($ fp );
1567+ /* We are able to establish a connection */
1568+ return true ;
15601569 } else {
1561- return false ; // Apache was not able to establish a connection
1570+ /* We are NOT able to establish a connection */
1571+ return false ;
15621572 }
15631573 }
15641574
@@ -1585,67 +1595,64 @@ private function _checkFtp($host, $port) {
15851595 return false ;
15861596 }
15871597 }
1588-
1589- /*
1590- * Set the state to the given level (or higher, but not lesser).
1591- * * If the actual state is critical and you call the method with ok,
1592- * then the state is critical.
1593- *
1594- * * If the actual state is critical and you call the method with error,
1595- * then the state is error.
1596- */
1597- private function _setState ($ oldState , $ newState )
1598- {
1599- /*
1600- * Calculate the weight of the old state
1601- */
1602- switch ($ oldState ) {
1603- case 'no_state ' : $ oldInt = 0 ;
1604- break ;
1605- case 'ok ' : $ oldInt = 1 ;
1606- break ;
1607- case 'unknown ' : $ oldInt = 2 ;
1608- break ;
1609- case 'info ' : $ oldInt = 3 ;
1610- break ;
1611- case 'warning ' : $ oldInt = 4 ;
1612- break ;
1613- case 'critical ' : $ oldInt = 5 ;
1614- break ;
1615- case 'error ' : $ oldInt = 6 ;
1616- break ;
1617- }
1618- /*
1619- * Calculate the weight of the new state
1620- */
1621- switch ($ newState ) {
1622- case 'no_state ' : $ newInt = 0 ;
1623- break ;
1624- case 'ok ' : $ newInt = 1 ;
1625- break ;
1626- case 'unknown ' : $ newInt = 2 ;
1627- break ;
1628- case 'info ' : $ newInt = 3 ;
1629- break ;
1630- case 'warning ' : $ newInt = 4 ;
1631- break ;
1632- case 'critical ' : $ newInt = 5 ;
1633- break ;
1634- case 'error ' : $ newInt = 6 ;
1635- break ;
1636- }
1637-
1638- /*
1639- * Set to the higher level
1640- */
1641- if ($ newInt > $ oldInt ){
1642- return $ newState ;
1643- }
1644- else
1645- {
1646- return $ oldState ;
1647- }
1648- }
1598+
1599+ /**
1600+ * Set the state to the given level (or higher, but not lesser).
1601+ * * If the actual state is critical and you call the method with ok,
1602+ * then the state is critical.
1603+ *
1604+ * * If the actual state is critical and you call the method with error,
1605+ * then the state is error.
1606+ */
1607+ private function _setState ($ oldState , $ newState ) {
1608+ /*
1609+ * Calculate the weight of the old state
1610+ */
1611+ switch ($ oldState ) {
1612+ case 'no_state ' : $ oldInt = 0 ;
1613+ break ;
1614+ case 'ok ' : $ oldInt = 1 ;
1615+ break ;
1616+ case 'unknown ' : $ oldInt = 2 ;
1617+ break ;
1618+ case 'info ' : $ oldInt = 3 ;
1619+ break ;
1620+ case 'warning ' : $ oldInt = 4 ;
1621+ break ;
1622+ case 'critical ' : $ oldInt = 5 ;
1623+ break ;
1624+ case 'error ' : $ oldInt = 6 ;
1625+ break ;
1626+ }
1627+ /*
1628+ * Calculate the weight of the new state
1629+ */
1630+ switch ($ newState ) {
1631+ case 'no_state ' : $ newInt = 0 ;
1632+ break ;
1633+ case 'ok ' : $ newInt = 1 ;
1634+ break ;
1635+ case 'unknown ' : $ newInt = 2 ;
1636+ break ;
1637+ case 'info ' : $ newInt = 3 ;
1638+ break ;
1639+ case 'warning ' : $ newInt = 4 ;
1640+ break ;
1641+ case 'critical ' : $ newInt = 5 ;
1642+ break ;
1643+ case 'error ' : $ newInt = 6 ;
1644+ break ;
1645+ }
1646+
1647+ /*
1648+ * Set to the higher level
1649+ */
1650+ if ($ newInt > $ oldInt ) {
1651+ return $ newState ;
1652+ } else {
1653+ return $ oldState ;
1654+ }
1655+ }
16491656
16501657 private function _getIntArray ($ line ) {
16511658 /** The array of float found */
0 commit comments