Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


icmp ping that doesn't require root

 
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates
Author Message
gilesw



Joined: 13 Sep 2003
Posts: 9

PostPosted: Thu Apr 10, 2008 5:36 am    Post subject: icmp ping that doesn't require root Reply with quote

Code:
   function ping_icmp() {
      /* ping me */
      if ($this->host["hostname"]) {
         /* initialize variables */
         $this->ping_status = "down";
         $this->ping_response = "ICMP Ping timed out";

         /* establish timeout variables */
         $to_sec = floor($this->timeout/1000);
         $to_usec = ($this->timeout%1000)*1000;

         /* clean up hostname if specifying snmp_transport */
         $this->host["hostname"] = str_replace("TCP:", "", $this->host["hostname"]);
         $this->host["hostname"] = str_replace("UDP:", "", $this->host["hostname"]);

         /* determine the host's ip address */
         $host_ip = gethostbyname($this->host["hostname"]);
         $this->ping_response = "$host_ip";
                  $ping_output = system("ping $host_ip -c 1", $retval);
         
                  preg_match('/rtt/', $ping_output, $ping_worked);
                  if ($ping_worked){
            $this->ping_status = 1000;
            $this->ping_response = "Host is alive";     
                        return true;
                  }else {
                      $this->response = "Host is dead";
                      return false;
                  }
           }
   }


I'd like to use cactid but it won't run ICMP unless it is running as root.

But this code certainly gets round any issues you may have with getting ICMP to work with cmd.php
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group