Module: nagvis Branch: master Commit: f57b1b820743a7aaffc08a432bf5ace3d877dfc8 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/commit/?id=f57b1b820743a7aaffc08a432bf5ace3d877dfc8
Author: r...@op5 <[email protected]> Date: Mon Jul 13 13:23:39 2009 +0300 Added a function to map a list of failed hosts to locations Signed-off-by: r...@op5 <[email protected]> --- share/netmap/Location.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-) diff --git a/share/netmap/Location.php b/share/netmap/Location.php index e98f396..2e787e2 100644 --- a/share/netmap/Location.php +++ b/share/netmap/Location.php @@ -153,6 +153,44 @@ class Location return $locations; } + + /** + * @param array $hosts + * @return array of Location + */ + public function getByFailedHosts($hosts = array()) + { + $result = array(); + $locations = $this->getAll(); + + $all_hosts = array(); + $failed_hosts = array(); + + if (($lines = file('hosts.all', FILE_IGNORE_NEW_LINES)) === FALSE) + throw new Exception('Could not read hosts.all'); + + foreach ($lines as $line) + { + $fields = explode('|', $line); + $all_hosts[$fields[0]] = $fields[1]; + } + + if (($lines = file('hosts.failed', FILE_IGNORE_NEW_LINES)) === FALSE) + throw new Exception('Could not read hosts.failed'); + + foreach ($lines as $line) + { + $fields = explode('|', $line); + $failed_hosts[$fields[0]] = false; /* dummy value, may be used in future */ + } + + foreach (array_unique(array_values(array_intersect_key($all, $failed))) as $location_id) + foreach ($locations as $location) + if ($location->id == $location_id) + $result[] = $location; + + return $result; + } } ?> ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
