mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
More appropriate state colours for MS Teams alerts (#10911)
* More appropriate state colours for MS Teams alerts * Split colour lookup to new function to keep Code Climate happy * Remove bits of whitespace
This commit is contained in:
@@ -27,10 +27,10 @@ class Msteams extends Transport
|
||||
public function contactMsteams($obj, $opts)
|
||||
{
|
||||
$url = $opts['url'];
|
||||
$color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000');
|
||||
|
||||
$data = array(
|
||||
'title' => $obj['title'],
|
||||
'themeColor' => $color,
|
||||
'themeColor' => self::getColorForState($obj['state']),
|
||||
'text' => strip_tags($obj['msg'], '<strong><em><h1><h2><h3><strike><ul><ol><li><pre><blockquote><a><img><p>')
|
||||
);
|
||||
$curl = curl_init();
|
||||
@@ -51,6 +51,24 @@ class Msteams extends Transport
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hex color string for a particular state
|
||||
* @param integer $state State code from alert
|
||||
* @return string Hex color, default to #337AB7 blue if state unrecognised
|
||||
*/
|
||||
public static function getColorForState($state)
|
||||
{
|
||||
$colors = array(
|
||||
0 => '#00FF00', // OK - green
|
||||
1 => '#FF0000', // Bad - red
|
||||
2 => '#337AB7', // Acknowledged - blue
|
||||
3 => '#FF0000', // Worse - red
|
||||
4 => '#F0AD4E', // Better - yellow
|
||||
);
|
||||
|
||||
return isset($colors[$state]) ? $colors[$state] : '#337AB7';
|
||||
}
|
||||
|
||||
public static function configTemplate()
|
||||
{
|
||||
|
Reference in New Issue
Block a user