Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to ping servers #35

Closed
dopeh opened this issue Mar 24, 2014 · 7 comments
Closed

Add option to ping servers #35

dopeh opened this issue Mar 24, 2014 · 7 comments
Assignees
Labels
enhancement Feature request

Comments

@dopeh
Copy link
Member

dopeh commented Mar 24, 2014

The current service functionality is only able to check whether a service is listening on a certain port. If you just want to ping a server without a specific port and check for response yes/no, this is not possible. A situation where a ping could be useful is for checking dyndns hostnames.
Because it is a different protocol it can not be checked with the current fsockopen(). The suggestion is to use port no. 1 for pings. So if a service is added with port=1, no fsockopen() will be used but instead an exec() to execute the ping program.

@dopeh dopeh added this to the 2.3.0 milestone Mar 24, 2014
@Abawell
Copy link
Contributor

Abawell commented Mar 24, 2014

Or you could add a third type. You would have Ping, Website or Service.
Other possibility: Having several test type for all server and select what services must be tested.
Than you could extend the tests to ftp, pop, imap and more...
That's the solution used by professional server monitoring applications. The problem in our case is, the php script execution time is limited to 30 s.

@dopeh dopeh self-assigned this Apr 4, 2014
@dopeh dopeh modified the milestones: 3.1.0, 3.0.1 Apr 5, 2014
@bereldhuin
Copy link

+1 for this option

Here is a function I found to use ping with pure php (adapted from the php website : http://www.php.net/manual/en/function.socket-create.php) :

function ping($host, $timeout = 1) {
/* ICMP ping packet with a pre-calculated checksum */
$package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
if(@socket_connect($socket, $host, null)){;
$ts = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255)){
$result = round((microtime(true) - $ts) * 1000, 0);
}
else {
$result = -1;
}
socket_close($socket);
}
else {
echo socket_last_error() . ' '. socket_strerror(socket_last_error());
$result = -1;
}
return $result;
}

I tested it on Windows 7, with Xammp / php5.3 and Debian 7 / php 5.5
On Linux, it needs to have root privillege to create socket which is not a problem as the checks are don from command line

@nerdalertdk
Copy link
Contributor

@Abawell
You can change the execution time with htaccess ?

@nerdalertdk
Copy link
Contributor

See pull #92 :)

@dopeh dopeh removed this from the 3.1.0 milestone Aug 7, 2014
@insuman
Copy link

insuman commented Mar 5, 2015

AFTER 3 HOURS FINALLY GET A SOLUTION TO PING SERVER WITH PORT 1 ....

open StatusUpdater.class.php inside function updateService at the first line add this :

if (($this->server['port'])==1) {
    $timeout = 5;
    /* ICMP ping packet with a pre-calculated checksum */
    $package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
    $socket  = socket_create(AF_INET, SOCK_RAW, 1);
    socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
    socket_connect($socket, $this->server['ip'], null);
    $ts = microtime(true);
    socket_send($socket, $package, strLen($package), 0);
    if (socket_read($socket, 255)) {
        $status = true;
    } else {
    //check error --   echo socket_last_error() . ' '. socket_strerror(socket_last_error());
        $status = false;    
    }
$this->rtime = (microtime(true) - $starttime);
    socket_close($socket);
    } else 

//rest of code 

{   

now add a server ip with port =1 and you will be able to ping it

remember for win7 you must execute as admin you have to do this :

Command Prompt > (Run as administrator)
net user administrator /active:yes

you have to change also response time second to milisecond

@sadortun sadortun modified the milestone: 4.0 Apr 30, 2016
@sadortun
Copy link
Member

PR in progress #102

@insuman
Copy link

insuman commented Aug 8, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request
Projects
None yet
Development

No branches or pull requests

6 participants