Powershell for check_mk custom monitoring practices

Source: Internet
Author: User

Recently I have been studying check_mk, a monitoring tool based on Nagios, but it is easier to use than Nagios. This has aroused my interest and I am most concerned with the support for custom monitoring scripts. In practice in windows, the supported client scripts or plug-ins can be EXE, bat, vbs, and PS1. I use powershell to write monitoring scripts.

This article is suitable for people who have some knowledge of check_mk. For introduction and Setup of check_mk, click here to view: a new open-source monitoring tool named check_mk

In addition, if the description of this article is not clear enough, you can refer to the official documentation: http://mathias-kettner.de/checkmk_devel_agentbased.html

========================================================== ========================================================== ==================================

1. Create a custom monitoring script process_top5.ps1 on the client:

$ Dp = (get-process) | select-first 5 echo '<process_top5'> # This output is very important, used to tell the check_mk monitoring client which metrics have foreach ($ P in $ DP) {write-host $ p. name $ p. workingset}

The script is simple. Capture the first five processes of the current computer, and the output process name and memory usage. Copy this file to the client check_ck plug-in directory (c: \ Program Files (x86) \ check_mk \ plugins)

2. Enter "check_mk-D hostname" on the monitoring end and view the <process_top5> section in the returned content. Five processes are displayed.

[[[Windows PowerShell]]]<<<logwatch>>><<<process_top5>>>agent 19939328AlipaySecSvc 20549632aspnet_state 1511424check_mk_agent 9351168cmd 6447104<<<local>>>

Now you need to write a check script on the monitoring end to parse the return value of the client. The check script is located in the "/usr/share/check_mk/checks" Directory (the check script is written in Python, some things are not responsible, so there is no need to worry about Python ). Note that the file name must be the same as the new metric name (process_top5). The content is as follows:

Process_top5_default_values = (0000000,15000000) # defines the alarm threshold. The sequence does not matter. # inventory indicates the check list. The parameter info indicates the return item of the client. <process_top5>, the returned value inventory is used for the item parameter def inventory_process_top5 (Info): Inventory = [] for line in info: disk = line [0] field = int (line [1]) Inventory in check_process_top5. append (disk, "process_top5_default_values") return inventory # This is the check main function def check_process_top5 (item, Params, Info): warn, crit = Params # retrieve the threshold value defined in process_top5_default_values. Pay attention to the value assignment order. Here, the value of warn is 10000000, and the value of crit is 15000000 for line in info: If (line [0]) = item: celsius = int (line [1]) If Celsius> crit: Return (2, "mem is % d" % Celsius) Elif Celsius> warn: Return (1, "mem is % d" % Celsius) else: Return (0, "mem is % d" % Celsius) Return (3, "% s not found in Agent output" % item) # Add the check item check_info ["process_top5"] = {'check _ function': check_process_top5, 'ventory _ function': inventory_process_top5, 'service _ description' to check_mk ': '% s ',}

 

3. Run "check_mk-L | grep process_top5" to check whether the check is available on the monitoring end and add process_top5 to the corresponding host file.

[[email protected] ~]# check_mk --checks=process_top5 -I [hostname]process_top5      5 new checks

"5 new checks" indicates that process_top5 has added 5 metric items, which are actually 5 process items. These 5 items have been added to the autocheck file of the host, as shown below:

[[email protected] ~]# cat /var/lib/check_mk/autochecks/3.81.mk[  ("3.81", "process_top5", ‘AlipaySecSvc‘, process_top5_default_values),  ("3.81", "process_top5", ‘agent‘, process_top5_default_values),  ("3.81", "process_top5", ‘aspnet_state‘, process_top5_default_values),  ("3.81", "process_top5", ‘check_mk_agent‘, process_top5_default_values),  ("3.81", "process_top5", ‘cmd‘, process_top5_default_values),  (‘3.81‘, ‘df‘, ‘C:/‘, {}),  (‘3.81‘, ‘df‘, ‘D:/‘, {}),  (‘3.81‘, ‘df‘, ‘E:/‘, {}),  (‘3.81‘, ‘df‘, ‘F:/‘, {}),  (‘3.81‘, ‘df‘, ‘G:/‘, {}),  (‘3.81‘, ‘logwatch‘, ‘HardwareEvents‘, ""),  (‘3.81‘, ‘logwatch‘, ‘Windows PowerShell‘, ""),  (‘3.81‘, ‘mem.win‘, None, {}),  (‘3.81‘, ‘uptime‘, None, {}),  (‘3.81‘, ‘winperf_if‘, ‘01‘, {‘state‘: [‘1‘], ‘speed‘: 1000000000}),  (‘3.81‘, ‘winperf_if‘, ‘02‘, {‘state‘: [‘1‘], ‘speed‘: 1000000000}),  (‘3.81‘, ‘winperf_if‘, ‘03‘, {‘state‘: [‘1‘], ‘speed‘: 1000000000}),  (‘3.81‘, ‘winperf_if‘, ‘04‘, {‘state‘: [‘1‘], ‘speed‘: 1000000000}),  (‘3.81‘, ‘winperf_if‘, ‘05‘, {‘state‘: [‘1‘], ‘speed‘: 100000}),  (‘3.81‘, ‘winperf_if‘, ‘06‘, {‘state‘: [‘1‘], ‘speed‘: 100000}),  (‘3.81‘, ‘winperf_if‘, ‘07‘, {‘state‘: [‘1‘], ‘speed‘: 100000}),  (‘3.81‘, ‘winperf_if‘, ‘08‘, {‘state‘: [‘1‘], ‘speed‘: 100000}),  (‘3.81‘, ‘winperf_if‘, ‘09‘, {‘state‘: [‘1‘], ‘speed‘: 1410065408}),  (‘3.81‘, ‘winperf_if‘, ‘10‘, {‘state‘: [‘1‘], ‘speed‘: 100000}),  (‘3.81‘, ‘winperf_phydisk‘, ‘SUMMARY‘, diskstat_default_levels),  (‘3.81‘, ‘winperf_processor.util‘, None, winperf_cpu_default_levels),]

4. Open the check_mk monitoring page and view the service of the corresponding host. You can see the added five items.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.