Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Pull request for working hours filter in alert survey #53

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/sleep/kmoon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion phplib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
$nagios_tag_categories = array("" => "Untagged", "action" => "Action Taken", "noaction" => "No Action Taken");
$nagios_tag_category_map = array("issue" => "action", "issuetimeperiod" => "action", "viewissue" => "action", "incorrecttimeperiod" => "noaction",
"downtimeexpired" => "noaction", "downtimenotset" => "noaction", "thresholdincorrect" => "noaction", "checkfaulty" => "noaction");
$locales = array("UK" => "Europe/London", "ET" => "America/New_York", "PT" => "America/Los_Angeles");
$locales = array("UK" => "Europe/London", "ET" => "America/New_York", "PT" => "America/Los_Angeles","FR"=>"Europe/Paris");
$sleep_states = array(-1 => "Unknown", 0 => "Awake", 1 => "Asleep");
$sleep_state_icons = array(0 => "icon-eye-open", 1 => "icon-eye-close");
$sleep_state_levels = array(-1 => "Unknown", 1 => "NREM Stage 1", 2 => "NREM Stage 2", 3 => "NREM Stage 3", 4 => "REM");
Expand Down Expand Up @@ -682,3 +682,25 @@ function getPrettyTime($referencedate=0, $timepointer='', $measureby='', $autote
return false;
}
}

function IsWorkingHoursWithTZ($date) {
// This function is like the one above, except takes the timezone into account for accurate
// retrieval of the alerts sent to the user from Splunk. Can't afford to be an hour out here.
$oncall_timezone = getTeamOncallConfig('timezone');
//we extract working hours from config
$wanted_working_hours = getTeamOncallConfig('workinghours');
date_default_timezone_set($oncall_timezone);
$return_work_hours=explode("-",$wanted_working_hours[date("l",$date)]);
//we build to timestamp one with the starting working hours
// the second with the en of working hours for the selected day of week of our alert
$fork1=strtotime(date("Y/m/d",$date)." ".$return_work_hours[0]);
$fork2=strtotime(date("Y/m/d",$date)." ".$return_work_hours[1]);
//test if my date is between fork1 and fork2 and if yes, alert was fired during working hours
if ($date<$fork2 and $date>$fork1) {
return(true);
}
else {
return(false);
}
}

9 changes: 9 additions & 0 deletions phplib/config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ $teams = array(
"timezone" => "America/New_York",
"start" => "friday 18:00",
"end" => "friday 18:00",
"workinghours" => array(
"Monday" => "08:00-18:00",
"Tuesday" => "08:00-18:00",
"Wednesday" =>"08:00-18:00",
"Thursday" =>"08:00-18:00",
"Friday" => "08:00-18:00",
"Saturday" => "",
"Sunday" => "",
),
),
"weekly_hints" => array("jira", "github"),
"irc_channel" => "#ops"
Expand Down
1 change: 1 addition & 0 deletions phplib/nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<li><a tabindex="-1" href="set_locale.php?l=UK">London, UK</a></li>
<li><a tabindex="-1" href="set_locale.php?l=ET">Brooklyn, NY</a></li>
<li><a tabindex="-1" href="set_locale.php?l=PT">San Francisco, CA</a></li>
<li><a tabindex="-1" href="set_locale.php?l=FR">Paris, FR</a></li>
</ul>
</li>
<li class="dropdown">
Expand Down
8 changes: 7 additions & 1 deletion phplib/oncall.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ function printOnCallNotifications($on_call_name, $start, $end, $oncall_start, $o
} else {
$html .= "<tr>";
}
$html .= "<td>{$pretty_date}</td><td>{$n['hostname']}</td><td>{$n['service']}</td><td><pre><small>{$n['output']}</small></pre></td>";
if (IsWorkingHoursWithTZ($n['time'])) {
$html .= "<td>{$pretty_date}</td><td>{$n['hostname']}</td><td>{$n['service']}</td><td><pre><small>{$n['output']}</small></pre></td>";
}
else {
$ROOT_URL=getTeamConfig('root_url');
$html .= "<td><img src=\"{$ROOT_URL}/assets/sleep/kmoon.png\"/>&nbsp;{$pretty_date}</td><td>{$n['hostname']}</td><td>{$n['service']}</td><td><pre><small>{$n['output']}</small></pre></td>";
}
$html .= "<td><span class='label label-{$nagios_state_to_badge[$n['state']]}'>{$n['state']}</span></td>";

# Need to populate all the information into hidden fields so we get all the data back nicely when the form is submitted
Expand Down