Module: nagvis Branch: master Commit: d63945c89534fdba0d8eecb183d1be18e77e8df1 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/commit/?id=d63945c89534fdba0d8eecb183d1be18e77e8df1
Author: Roman Kyrylych <[email protected]> Date: Thu Aug 20 18:17:36 2009 +0300 gmap: Introduced State class Signed-off-by: Roman Kyrylych <[email protected]> --- share/netmap/Link.php | 7 +------ share/netmap/LinkService.php | 4 ++-- share/netmap/Location.php | 8 ++------ share/netmap/LocationService.php | 4 ++-- share/netmap/NagiosService.php | 28 ++++++++++++++-------------- share/netmap/State.php | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 30 deletions(-) diff --git a/share/netmap/Link.php b/share/netmap/Link.php index dd92154..dabf5fe 100644 --- a/share/netmap/Link.php +++ b/share/netmap/Link.php @@ -23,11 +23,6 @@ class Link { - const STATE_UNKNOWN = 0; - const STATE_OK = 1; - const STATE_WARNING = 2; - const STATE_ERROR = 3; - public $id; public $id1; public $id2; @@ -37,7 +32,7 @@ class Link public $state; public function __construct($id = '', $id1 = "", $id2 = "", $description = "", - $action = "", $object = null, $state = self::STATE_UNKNOWN) + $action = "", $object = null, $state = State::UNKNOWN) { $this->id = $id; $this->id1 = $id1; diff --git a/share/netmap/LinkService.php b/share/netmap/LinkService.php index 56d8484..cc8f2eb 100644 --- a/share/netmap/LinkService.php +++ b/share/netmap/LinkService.php @@ -50,7 +50,7 @@ class LinkService throw new Exception('Unknown object type in links.xml'); } else - $link->state = Link::STATE_UNKNOWN; + $link->state = State::UNKNOWN; } /** @@ -69,7 +69,7 @@ class LinkService self::updateState($link); - if (!$problemonly || $link->state != Link::STATE_OK) + if (!$problemonly || $link->state != State::OK) $links[] = $link; } diff --git a/share/netmap/Location.php b/share/netmap/Location.php index 5438959..9d75fa5 100644 --- a/share/netmap/Location.php +++ b/share/netmap/Location.php @@ -23,11 +23,6 @@ class Location { - const STATE_UNKNOWN = 0; - const STATE_OK = 1; - const STATE_WARNING = 2; - const STATE_ERROR = 3; - public $id; public $point; public $label; @@ -37,7 +32,8 @@ class Location public $object; public $state; - public function __construct($id = "", $point = "", $label = "", $address = "", $description = "", $action = "", $object = null, $state = self::STATE_UNKNOWN) + public function __construct($id = "", $point = "", $label = "", $address = "", + $description = "", $action = "", $object = null, $state = State::UNKNOWN) { $this->id = $id; $this->point = $point; diff --git a/share/netmap/LocationService.php b/share/netmap/LocationService.php index b737b19..8fd3c89 100644 --- a/share/netmap/LocationService.php +++ b/share/netmap/LocationService.php @@ -50,7 +50,7 @@ class LocationService throw new Exception('Unknown object type in locations.xml'); } else - $location->state = Location::STATE_UNKNOWN; + $location->state = State::UNKNOWN; } /** @@ -69,7 +69,7 @@ class LocationService self::updateState($location); - if (!$problemonly || $location->state != Location::STATE_OK) + if (!$problemonly || $location->state != State::OK) $locations[] = $location; } diff --git a/share/netmap/NagiosService.php b/share/netmap/NagiosService.php index 4b4a370..c2f721c 100644 --- a/share/netmap/NagiosService.php +++ b/share/netmap/NagiosService.php @@ -117,23 +117,23 @@ class NagiosService switch ($data['state']) { case 'ERROR': - return Location::STATE_ERROR; + return State::ERROR; case 'PENDING': - return Location::STATE_UNKNOWN; + return State::UNKNOWN; case 'UP': - return Location::STATE_OK; + return State::OK; case 'DOWN': - return Location::STATE_ERROR; + return State::ERROR; case 'UNREACHABLE': - return Location::STATE_WARNING; + return State::WARNING; case 'UNKNOWN': default: - return Location::STATE_UNKNOWN; + return State::UNKNOWN; } } @@ -147,23 +147,23 @@ class NagiosService switch ($data['state']) { case 'ERROR': - return Location::STATE_ERROR; + return State::ERROR; case 'PENDING': - return Location::STATE_UNKNOWN; + return State::UNKNOWN; case 'OK': - return Location::STATE_OK; + return State::OK; case 'WARNING': - return Location::STATE_WARNING; + return State::WARNING; case 'CRITICAL': - return Location::STATE_ERROR; + return State::ERROR; case 'UNKNOWN': default: - return Location::STATE_UNKNOWN; + return State::UNKNOWN; } } @@ -173,7 +173,7 @@ class NagiosService public function getHostGroupState($hostgroup) { $hosts = $this->backend->getHostsByHostgroupName($hostgroup->name); - $state = Location::STATE_UNKNOWN; + $state = State::UNKNOWN; foreach ($hosts as $host) $state = max($state, $this->getHostState(new Host($host))); @@ -187,7 +187,7 @@ class NagiosService public function getServiceGroupState($servicegroup) { $services = $this->backend->getServicesByServicegroupName($servicegroup->name); - $state = Location::STATE_UNKNOWN; + $state = State::UNKNOWN; foreach ($services as $service) $state = max($state, $this->getServiceState(new Service($service['host_name'], $service['service_description']))); diff --git a/share/netmap/State.php b/share/netmap/State.php new file mode 100644 index 0000000..b7f46b7 --- /dev/null +++ b/share/netmap/State.php @@ -0,0 +1,32 @@ +<?php + +/***************************************************************************** + * + * Copyright (C) 2009 NagVis Project + * + * License: + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + *****************************************************************************/ + +class State +{ + const UNKNOWN = 0; + const OK = 1; + const WARNING = 2; + const ERROR = 3; +} + +?> ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
