Adding the IP Address to the host details page

Information and discussions relating to the Nagios V-Shell web interface.

Adding the IP Address to the host details page

Postby as300182 » Thu Jun 23, 2016 3:24 am

I thought others might find this useful.

I edited the hostdetails.php page that can be found in the 'view' folder, as follows:

Add the following function to the foot of the file just before the close php tag.

Code: Select all
function get_host_ip($hostname){
   global $NagiosData;
   $data = $NagiosData->getProperty('hosts_objs');
   $ip = "Not found";
   foreach($data as $a){
      $name=$a['host_name'];
      if($name == $hostname){
         $ip = $a['address'];
         break;
      }
   }
   return $ip;
}


Now go to this section of the code near the top of the file

Code: Select all
   <h3>".gettext('Host Status Detail')."</h3>
   <div class='detailWrapper'>
   <h4><em>".gettext('Host').": </em>{$dets['Host']}</h4>
   <h5><em>".gettext('Member of').": </em>{$dets['MemberOf']}</h5>
   <h5><a href='index.php?type=services&host_filter={$dets['Host']}' title='".gettext('See All Services For This Host')."'>".gettext('See All Services For This Host')."</a></h5>
   <div class='detailcontainer'>
   <fieldset class='hostdetails'>


and add the line <h5><em>IP Address: </em>".get_host_ip($dets['Host'])."</h5> to output the ip address.

Code: Select all
   <h3>".gettext('Host Status Detail')."</h3>
   <div class='detailWrapper'>
   <h4><em>".gettext('Host').": </em>{$dets['Host']}</h4>
   <h5><em>IP Address: </em>".get_host_ip($dets['Host'])."</h5>
   <h5><em>".gettext('Member of').": </em>{$dets['MemberOf']}</h5>
   <h5><a href='index.php?type=services&host_filter={$dets['Host']}' title='".gettext('See All Services For This Host')."'>".gettext('See All Services For This Host')."</a></h5>
   <div class='detailcontainer'>
   <fieldset class='hostdetails'>


I expect this could be used almost anywhere you need the ip address, but this does it for me. Works with VShell 1.9. Don't know about the latest version of 2.x as I haven't had a chance to look at that yet.
as300182
 
Posts: 35
Joined: Tue May 17, 2016 8:09 am

Re: Adding the IP Address to the host details page

Postby rkennedy » Thu Jun 23, 2016 9:48 am

Thanks for the contribution! Do you think you could make a pull request on the official GitHub page so that this could be added? https://github.com/NagiosEnterprises/nagiosvshell
Former Nagios Employee
rkennedy
 
Posts: 6581
Joined: Mon Oct 05, 2015 11:45 am

Re: Adding the IP Address to the host details page

Postby as300182 » Thu Jun 23, 2016 2:45 pm

I'd happily make a pull request but don't pull requests let you tell others about changes you've pushed to a GitHub repository? Because I've not pushed anything to the GitHub repository. Do you want me to raise a pull request regardless and just add what I've put on this forum?
as300182
 
Posts: 35
Joined: Tue May 17, 2016 8:09 am

Re: Adding the IP Address to the host details page

Postby tmcdonald » Thu Jun 23, 2016 4:27 pm

A pull request allows you to request that a change you have made in a fork of a project be "pulled" into the main project. So the workflow here would be to fork v-shell from us, make your updates, push/commit your updates to your own fork, then make the pull request. Then we will look at and compare the changes, and decide whether to include them.
Former Nagios employee
tmcdonald
 
Posts: 9118
Joined: Mon Sep 23, 2013 8:40 am

Re: Adding the IP Address to the host details page

Postby as300182 » Fri Jun 24, 2016 1:00 pm

I've made a small adjustment to the function to avoid looping through the the host objects every time, as it was pointed out that in a large environment this could be time consuming. It now looks like this:

Code: Select all
function get_host_ip($hostname){
   global $NagiosData;
   $data = $NagiosData->getProperty('hosts_objs');
   $hostobject = $data[$hostname];
   $ip = $hostobject['address'];
   if ($ip == NULL){
      $ip = "Not found";
   }
   return $ip;
}


I've put this into my own fork and created a pull request as follows:

https://github.com/NagiosEnterprises/na ... ll/pull/17

:-)
as300182
 
Posts: 35
Joined: Tue May 17, 2016 8:09 am

Re: Adding the IP Address to the host details page

Postby mcapra » Fri Jun 24, 2016 1:01 pm

Thanks again for sharing! Looks like the commit was received by the dev.
Former Nagios employee
http://www.mcapra.com/
User avatar
mcapra
 
Posts: 3423
Joined: Thu May 05, 2016 3:54 pm


Return to Nagios V-Shell

Who is online

Users browsing this forum: No registered users and 1 guest