Logo Search packages:      
Sourcecode: nagstamon version File versions  Download package

def Nagstamon::nagstamonObjects::NagiosServer::GetHost (   self,
  host 
)

find out ip or hostname of given host to access hosts/devices which do not appear in DNS but
have their ip saved in Nagios

Definition at line 551 of file nagstamonObjects.py.

00551                            :
        """
        find out ip or hostname of given host to access hosts/devices which do not appear in DNS but
        have their ip saved in Nagios
        """
        
        # initialize ip string
        ip = ""

        # glue nagios cgi url and hostinfo 
        nagcgiurl_host  = self.nagios_cgi_url + "/extinfo.cgi?type=1&host=" + host
        
        # get host info
        htobj = self.FetchURL(nagcgiurl_host, giveback="dict")
        
        try:
            # take ip from object path
            ip = str(htobj.body.table.tr.td[1].div[5].text)
            # Workaround for Nagios 3.1 where there are groups listed whose the host is a member of
            if ip == "Member of":
                ip = str(htobj.body.table.tr.td[1].div[7].text)
            # print IP in debug mode
            if str(self.conf.debug_mode) == "True":    
                print "IP of %s:" % (host), ip
            # when connection by DNS is not configured do it by IP
            if str(self.conf.connect_by_dns_yes) == "True":
                # try to get DNS name for ip, if not available use ip
                try:
                    host = socket.gethostbyaddr(ip)[0]
                except:
                    host = ip
            else:
                host = ip
        except:
            host = "ERROR"
         
        # do some cleanup
        del htobj    

        # give back host or ip
        return host
    
    
    def __del__(self):


Generated by  Doxygen 1.6.0   Back to index