This repository was archived by the owner on Nov 24, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.ps1
More file actions
135 lines (116 loc) · 6.2 KB
/
Copy pathbasic.ps1
File metadata and controls
135 lines (116 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# -------------------------------------------------------------------------------- #
# Description #
# -------------------------------------------------------------------------------- #
# The script presented here is a simple Nagios check example, employing a set of #
# utility functions to guarantee accurate output and exit codes. Although this #
# version uses fixed values, suitable for straightforward checks, we also offer a #
# more sophisticated variant that demonstrates how to handle command-line #
# arguments for more elaborate or flexible scripting. #
# -------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------- #
# Main() #
# -------------------------------------------------------------------------------- #
# This function is where you can include all the code related to the check. You're #
# free to define additional functions and invoke them whenever necessary. #
# #
# In this template, we've generated a random number to illustrate how to call the #
# core functions that manage the different states. However, real tests will be #
# more intricate and elaborate, but they should adhere to the same fundamental #
# structure. #
# -------------------------------------------------------------------------------- #
function main {
$critical_level = 90
$warning_level = 75
$test_value = (Get-Random -Minimum 1 -Maximum 101)
if ($test_value -ge $critical_level) {
handle_critical "Test Value = $test_value"
}
elseif ($test_value -ge $warning_level) {
handle_warning "Test Value = $test_value"
}
elseif ($test_value -ge 0) {
handle_ok "Test Value = $test_value"
}
else {
handle_unknown "Test Value = $test_value"
}
}
# -------------------------------------------------------------------------------- #
# STOP HERE! #
# -------------------------------------------------------------------------------- #
# The functions listed below are integral to the template and do not necessitate #
# any modifications to use this template. If you intend to make changes to the #
# code beyond this point, please make certain that you comprehend the consequences #
# of those alterations! #
# -------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------- #
# Handle OK #
# -------------------------------------------------------------------------------- #
# If provided with a message, this function will show it with the 'OK' prefix and #
# subsequently terminate the script with the requisite exit code of 0. #
# -------------------------------------------------------------------------------- #
function handle_ok {
param (
[string]$message
)
if ($message) {
Write-Host "OK - $message"
}
exit 0
}
# -------------------------------------------------------------------------------- #
# Handle Warning #
# -------------------------------------------------------------------------------- #
# If provided with a message, this function will show it with the 'WARNING' prefix #
# and subsequently terminate the script with the requisite exit code of 1. #
# -------------------------------------------------------------------------------- #
function handle_warning {
param (
[string]$message
)
if ($message) {
Write-Host "WARNING - $message"
}
exit 1
}
# -------------------------------------------------------------------------------- #
# Handle Critical #
# -------------------------------------------------------------------------------- #
# If provided with a message, this function will show it with the 'CRITICAL' #
# prefix and subsequently terminate the script with the requisite exit code of 2. #
# -------------------------------------------------------------------------------- #
function handle_critical {
param (
[string]$message
)
if ($message) {
Write-Host "CRITICAL - $message"
}
exit 2
}
# -------------------------------------------------------------------------------- #
# Handle Unknown #
# -------------------------------------------------------------------------------- #
# If provided with a message, this function will show it with the 'UNKNOWN' prefix #
# and subsequently terminate the script with the requisite exit code of 3. #
# -------------------------------------------------------------------------------- #
function handle_unknown {
param (
[string]$message
)
if ($message) {
Write-Host "UNKNOWN - $message"
}
exit 3
}
# -------------------------------------------------------------------------------- #
# The Core #
# -------------------------------------------------------------------------------- #
# This is the central component of the script. #
# -------------------------------------------------------------------------------- #
main
# -------------------------------------------------------------------------------- #
# End of Script #
# -------------------------------------------------------------------------------- #
# This is the end - nothing more to see here. #
# -------------------------------------------------------------------------------- #