Skip to content

Commit 537f778

Browse files
committed
add uri_clean attribute, removes the leading backslash for uris that have only one leading backslash i.e saved at root
change the detail syntax, use uri_clean , include a formatted most_recent_run_time and print the exit code directly change default empty state to unknown for cases where user specifies title in filters, thresholds or directly in the arguent, change the empty result syntax and warn about title attribute usage
1 parent 20122aa commit 537f778

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

pkg/snclient/check_tasksched.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ func (l *CheckTasksched) Build() *CheckData {
4747
defaultFilter: "enabled = true",
4848
defaultCritical: "exit_code < 0",
4949
defaultWarning: "exit_code != 0",
50-
detailSyntax: "${uri}: ${exit_code} != 0",
50+
detailSyntax: "${uri_clean} (%{most_recent_run_time:date}) exited with ${exit_code}",
5151
topSyntax: "%(status) - ${problem_list}",
5252
okSyntax: "%(status) - All tasks are ok",
5353
emptySyntax: "%(status) - No tasks found",
54-
emptyState: CheckExitWarning,
54+
emptyState: CheckExitUnknown,
5555
attributes: []CheckAttribute{
5656
{name: "application", description: "Name of the application that the task is associated with"},
5757
{name: "comment", description: "Comment or description for the work item"},
@@ -60,6 +60,8 @@ func (l *CheckTasksched) Build() *CheckData {
6060
{name: "exit_code", description: "The last jobs exit code"},
6161
{name: "exit_string", description: "The last jobs exit code as string"},
6262
{name: "folder", description: "Task folder"},
63+
{name: "uri", description: "Fully qualified path to the task, includes folder and the task title"},
64+
{name: "uri_clean", description: "Remove the leading backslash from the URI, only for tasks directly saved at root and not for ones saved inside folders."},
6365
{name: "has_run", description: "True if this task has ever been executed"},
6466
{name: "max_run_time", description: "Maximum length of time the task can run", unit: UDuration},
6567
{name: "most_recent_run_time", description: "Most recent time the work item began running", unit: UDate},

pkg/snclient/check_tasksched_windows.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
_ "embed"
88
"fmt"
99
"strconv"
10+
"strings"
1011
"syscall"
1112
"time"
1213

@@ -78,6 +79,7 @@ func (l *CheckTasksched) addTasks(ctx context.Context, snc *Agent, check *CheckD
7879
"exit_string": task.LastTaskResult.String(),
7980
"folder": task.Path,
8081
"uri": task.URI,
82+
"uri_clean": parseURIClean(task.URI),
8183
"has_run": fmt.Sprintf("%t", hasRun),
8284
"max_run_time": task.ExecutionTimeLimit,
8385
"most_recent_run_time": fmt.Sprintf("%d", l.parseDate(task.LastRunTime).Unix()),
@@ -92,9 +94,24 @@ func (l *CheckTasksched) addTasks(ctx context.Context, snc *Agent, check *CheckD
9294
check.listData = append(check.listData, entry)
9395
}
9496

97+
if check.HasThreshold("title") || check.hasThresholdCond(check.filter, "title") || l.TaskTitle != CheckTaskschedDefaultTaskTitle {
98+
check.emptyState = CheckExitUnknown
99+
check.emptySyntax = "%(status) - No tasks found, check your arguments/filters/thresholds using title attribute."
100+
}
101+
95102
return nil
96103
}
97104

105+
func parseURIClean(uri string) string {
106+
if strings.Count(uri, "\\") == 1 {
107+
if cut, cutOk := strings.CutPrefix(uri, "\\"); cutOk {
108+
return cut
109+
}
110+
}
111+
112+
return uri
113+
}
114+
98115
func (l *CheckTasksched) parseDate(raw string) time.Time {
99116
// date matches the pattern /Date(unixmilliseconds))/
100117
if len(raw) > 6 && raw[0:6] == "/Date(" {

0 commit comments

Comments
 (0)