I have some services by icinga2 monitor
But I want to achieve more than the existing
please how to custom monitor 。
I wonder if there is such a blog tutorial
tks.!
thankyou michael ,I read this document ,but I still don’t understand
I think I write my shell scripts for monitor
Hi,
which parts are not that clear? Plugin scripts, adding a check command, integrating them as a service apply rule?
Where are you currently at, e.g. with a simple check you’d want to add to your monitoring?
Cheers,
Michael
If I want to monitor the port without using the official script
i write a scritps in /server/scripts
how to define using this script
Hi,
in case of monitoring a port, I’d suggest using the check_tcp plugin provided as part of the monitoring/nagios plugin package. You’ll install that already with following the installation documentation.
And you don’t need to create a CheckCommand configuration object either since this covered within the Icinga Template Library as well - tcp.
object Host "abc" {
check_command = "hostalive"
address = "..."
vars.ports = [ 22, 80, 443 ]
vars.os = "Linux"
}
// Simple apply
apply Service "tcp 22" {
check_command = "tcp"
vars.tcp_port = 22
assign where host.vars.os == "Linux"
}
// Advanced apply for
apply Service "tcp " for (p in host.vars.ports) {
check_command = "tcp"
vars.tcp_port = p
}
References:
- https://icinga.com/docs/icinga2/latest/doc/03-monitoring-basics/#custom-variables
- https://icinga.com/docs/icinga2/latest/doc/03-monitoring-basics/#apply-rules
- https://icinga.com/docs/icinga2/latest/doc/03-monitoring-basics/#passing-check-command-parameters-from-host-or-service
Cheers,
Michael
sorry ,Maybe i’m wrong ,It’s not like this
I said production
Need to monitor collections in mongo
If so how can I customize it in icinga
Hi,
I’d appreciate it if you go into more detail, and allow others helping you for the fun and pride to get a better picture of what you’re trying to do. Provide setup examples, listening APIs, etc. from your environment.
Cheers,
Michael
thank you I found here can also customize the monitoring
I want to add script through here
How to define warnings in the script
Do you mean define warning levels or define the script output for display warning state in Icinga2?
Maybe here’s a possible point of start:
https://icinga.com/docs/icinga2/latest/doc/05-service-monitoring/#plugin-api
Define script to display warnings
Comparing the result and setting the correct level:
if ( [ “echo "$tps >= $crit_tps" | bc
” == “1” ] || [ “echo "$read >= $crit_read" | bc -q
” == “1” ] ||
[ “echo "$written >= $crit_written" | bc
” == “1” ] ); then
msg=“CRITICAL”
status=2
else if ( [ “echo "$tps >= $warn_tps" | bc
” == “1” ] || [ “echo "$read >= $warn_read" | bc
” == “1” ] ||
[ “echo "$written >= $warn_written" | bc
” == “1” ] ); then
msg=“WARNING”
status=1
else
msg=“OK”
status=0
fi
fi
Bye!
exit $status
Does icinga2 recognize alarms like this?
Should work, but you have to insert echo $msg
before exit $status
so yo get a readable status message in Icinga.
if [ “${result}” = 0 ]
then
msg=“CRITICAL”
status=2
elif [ “${result}” -ge 20 ]
then
msg=“WARNING”
status=1
else
msg=“OK”
status=0
fi
echo “$host $port is $msg”
exit $status
My script is defined like this
$status=0 1 。。。
exit $status Is it necessary
Icinga2 evaluates the return values of the scripts as follows
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
The output which is shown in icingaweb2 depends on the output provided by the script, e.g:
...
echo "oh no! something went wrong ..."
exit 2
… would output something like this:
thank you all
I understand
Hi,
Is there a way to output a message via a variable?
For example I want to print a variable which contains multiple lines from some previous results.
Is this possible?
When I try to do:
...
echo "$variable"
exit 0
It doesn’t work. Do I do something wrong?
Hi.
This should work. Usually (monitoring-)scripts produce output, which will be visible in icingaweb2.
The output from the (monitoring-)script should simply get displayed, whatever it is.
A good starting point to debug this issue is to run the script with the same options and arguments on the commandline.
Do you get output when running the script on the commandline?
If this doesn’t help, could you give us some more information about the script and where you expect the output to be visible (icingaweb2, commandline)?
Sidenote: Maybe it is good idea to start a new thread for your question.
Greetings.