mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-06-09 08:42:14 -04:00
Add ServiceStates::int()
This commit is contained in:
parent
fb8b843249
commit
c600b0640f
1 changed files with 34 additions and 0 deletions
|
|
@ -17,6 +17,40 @@ class ServiceStates
|
|||
|
||||
const PENDING = 99;
|
||||
|
||||
/**
|
||||
* Get the integer value of the given textual service state
|
||||
*
|
||||
* @param string $state
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \InvalidArgumentException If the given service state is invalid, i.e. not known
|
||||
*/
|
||||
public static function int($state)
|
||||
{
|
||||
switch (strtolower($state)) {
|
||||
case 'ok':
|
||||
$int = self::OK;
|
||||
break;
|
||||
case 'warning':
|
||||
$int = self::WARNING;
|
||||
break;
|
||||
case 'critical':
|
||||
$int = self::CRITICAL;
|
||||
break;
|
||||
case 'unknown':
|
||||
$int = self::UNKNOWN;
|
||||
break;
|
||||
case 'pending':
|
||||
$int = self::PENDING;
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Invalid service state %d', $state));
|
||||
}
|
||||
|
||||
return $int;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the textual representation of the passed service state
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue