From c2979b7d4128095cdcc35c22a0a4d68fa51affd2 Mon Sep 17 00:00:00 2001 From: Rune Darrud Date: Fri, 31 Jul 2015 21:23:06 +0200 Subject: [PATCH] Minor bugfixes, updated readme and made a default configuration file. --- README.md | 257 ++++++++++++++++++++++------------ Solution/check_iis/Program.cs | 170 +++++++++++----------- check_iis.conf | 192 +++++++++++++++++++++++++ 3 files changed, 454 insertions(+), 165 deletions(-) create mode 100644 check_iis.conf diff --git a/README.md b/README.md index 061fbcd..05ebf48 100644 --- a/README.md +++ b/README.md @@ -13,40 +13,99 @@ Internet Information Server check plugin for Icinga2, Icinga, Centreon, Shinken, ## Assumptions This executable assumes the following: * That the plugin is able to run as SYSTEM or with a user that has Administrative privileges. -* When you run inventory with the switch to only return running services, this assumes that the Sites and AppPools are in their correct states. The output from this can be used to correctly configure the arguments. +* When you run inventory with the switch to only return running objects, this assumes that the Sites and AppPools are in their correct states. The output from this can be used to correctly configure the arguments. +* If you run this plugin via Icinga2 and you have issues escaping, try to supply --split-by and separate multiple AppPools or Sites with a comma, ex ".Net v2.0,.Net v4.5". +* Some monitoring solutions really dont like long verbose output, so if your monitoring solution is one of these, try to use the switch --hide-long-output so it only prints the summary of the --check-service. ## Usage: - check_iis.exe - Windows Service Status plugin for Icinga2, Icinga, Centreon, Shinken, Naemon and other nagios like systems. - Version: 0.9.5690.4962 + check_iis.exe - Windows Service Status plugin for Icinga2, Icinga, Centreon, Shinken, Naemon and other nagios like systems + Version: 0.9.5690.38448 - a:inventory-apppools Switch to use to provide inventory of AppPools. - A:inventory-websites Switch to use to provide inventory of Sites - B:check-websites Switch to use to check the health status of the local Sites - C:check-apppools Switch to use to check the health status of the local AppPools + a:inventory-websites Switch to use to provide inventory of Sites + A:inventory-apppools Switch to use to provide inventory of AppPools + b:check-websites Switch to use to check the health status of the local Sites + B:check-apppools Switch to use to check the health status of the local AppPools E:inv-level Argument to change the level of output. Default is 'normal', available options are 'normal','full' f:inv-format Argument to provide output of the inventory in other formats, valid options are 'readable', 'i2conf' and 'json' - F:excluded-sites Excludes Sites from checks and inventory. Provide multiple with spaces between - G:included-sites Includes Sites to check while all other Sites are excluded, affects both checks and inventory. Provide multiple with spaces between - h:stopped-sites The specified Sites are checked that they are stopped. Provide multiple with spaces between - H:warn-sites These specified Sites will return Warning if they are not in the expected state. Provide multiple with spaces between - i:perfcounter-sites Switch to use to get perfcounters from local Sites - I:excluded-apppools Excludes AppPools from checks and inventory. Provide multiple with spaces between - J:included-apppools Includes apppools to check while all other AppPools are excluded, affects both checks and inventory. Provide multiple with spaces between - k:stopped-apppools The specified AppPools are checked that they are stopped. Provide multiple with spaces between - K:warn-apppools The specified AppPools will return Warning if they are not in the expected state. Provide multiple with spaces between - l:perfcounter-apppools Switch to use to get perfcounters from local AppPools - L:skip-empty-apppools Switch which sets do not inventory AppPools which are empty or unused. - T:hide-long-output Switch to hide the long service output, only prints the summary output and any Sites or Services deviating from 'OK' + F:excluded-sites Excludes Sites from checks and inventory + G:included-sites Includes Sites to check while all other Sites are excluded, affects both checks and inventory + h:stopped-sites The specified Sites are checked that they are stopped + H:warn-sites These specified Sites will return Warning if they are not in the expected state + i:perfcounter-sites Switch to use to get perfcounters from Sites + I:excluded-apppools Excludes AppPools from checks and inventory + J:included-apppools Includes AppPools to check while all other AppPools are excluded, affects both checks and inventory + k:stopped-apppools The specified AppPools are checked that they are stopped + K:warn-apppools The specified AppPools will return Warning if they are not in the expected state + l:perfcounter-apppools Switch to use to get perfcounters from AppPools + L:skip-empty-apppools Switch which sets do not check or inventory AppPools which are empty + T:hide-long-output Switch to hide the long service output, only prints the summary output and any Sites or AppPools deviating from 'OK' u:expected-state Argument to provide the expected State of the AppPool or Site, used together with --single-check w:icinga2 Switch used in the Icinga2 CommandDefinition, returns output and perfcounter to the correct class. Do not use via command line. - W:single-check Switch used together with the Icinga2 Auto Apply rules, this is set when there is a single Site or AppPool to check. Do take great care if you use this outside of the auto apply rules. - x:split-by Argument used to specify what splits all Sites and AppPool arguments. Default is a single space, ' '. - X:inv-hide-empty Switch to hide empty vars from inventory output. + W:single-check Switch used together with the Icinga2 Auto Apply rules, this is set when there is a single Site or AppPool to check. Do take great care if you use this outside of the auto apply rules + x:split-by Argument used to specify what splits all Sites and AppPool arguments. Default is a single space, ' ' + X:inv-hide-empty Switch to hide empty vars from inventory output y:inv-running-only Switch to only inventory running Sites and/or AppPools, depending on what has been selected for inventory - z:verbose Switch to use when trying to figure out why a service is not included, excluded or similarly when the returned output is not as expected + z:verbose Switch to use when trying to figure out why a Site or an AppPool is not included, excluded or similarly when the returned output is not as expected Z:debug Switch to to get maximum verbosity (for debugging) +## QuickStart - Icinga2 + +### Recommended setup to start with + +To get quickly started with this plugin, these are the steps needed to quickly get going: + +#### Copy the neccesary files + +To make available the plugin for icinga2: +* Copy the two files "check_iis.exe" and "check_iis.exe.config" to the sbin folder of icinga2 +** Default path on a 32bit OS: C:\Program Files\ICINGA2\sbin +** Default path on a 64bit OS: C:\Program Files (x86)\ICINGA2\sbin + +* Copy the configuration file "check_iis.conf" into a place where it is easy for you to modify this using Notepad++ or your favourite text editor, like your Documents + +** Note, this is only the command definition +* Make a decision if you want to monitor each AppPool separately or as a group. +* Make a decision if you want to monitor each Site separately or as a group. +#### Inventory Sites +* Skip this step if you are going to monitor the Sites as a group. +* Copy the output from this command to hosts.conf inside the brackets of the Host object (must be run from within icinga2's sbin folder, where you copied check_iis.exe and check_iis.exe.config) + + check_iis.exe --inventory-websites --inv-format i2conf + +#### Monitoring Inventoried Sites +* Skip this step if you are going to monitor the Sites as a group. +* Uncomment the apply Service rule called "Monitoring Inventoried AppPools" in the check_iis.conf + +#### Monitoring Sites as a group +* Skip this step if you are going to monitor Sites based on the inventory. +* Uncomment the apply Service rule called "Monitoring Sites as group" in the check_iis.conf + +#### Inventory AppPools +* Skip this step if you are going to monitor the Application Pools as a group. + +* Copy the output from this command to hosts.conf inside the brackets of the Host object (must be run from within icinga2's sbin folder, where you copied check_iis.exe and check_iis.exe.config) + + check_iis.exe --inventory-apppools --inv-format i2conf + +#### Monitoring Inventoried AppPools +* Skip this step if you are going to monitor the Application Pools as a group. +* Uncomment the apply Service rule called "Monitoring Inventoried AppPools" in the check_iis.conf + +#### Monitoring AppPools as a group +* Skip this step if you are going to monitor AppPools based on the inventory. +* Uncomment the apply Service rule called "Monitoring AppPools as group" in the check_iis.conf + +#### Copying the configuration file to icinga + +Copy the configuration file "check_iis.conf" into your ICINGA2\etc\icinga2\conf.d folder from where you modified a copy of the default. + +#### Applying the configuration change + +Restart icinga2 agent on the local server/client to read the changed configuration. + +Wait 1-2 minutes, then on the master, run "icinga2 node update-config" before restarting the icinga2 service to read the "discovered" services from the agent(s). + ## Examples ### Monitoring @@ -230,126 +289,149 @@ All configuration samples below assumes local configuration on agent, configurat command = [ PluginDir + "/check_iis.exe" ] arguments = { - "--check-apppools" = { - set_if = "$iis_check_apppools$" - description = "Parameter to use to check the health status of the local Sites" - } - "--check-websites" = { - set_if = "$iis_check_sites$" - description = "Parameter to use to check the health status of the local Sites" + "--inventory-websites" = { + set_if = "$iis_inventory_sites$" + description = "Switch to use to provide inventory of Sites" } "--inventory-apppools" = { set_if = "$iis_inventory_apppools$" - description = "Parameter to use to provide inventory of apppools instead of checking for the health." + description = "Switch to use to provide inventory of AppPools" } - "--inventory-websites" = { - set_if = "$iis_inventory_sites$" - description = "Parameter to use to provide inventory of sites instead of checking for the health." + "--check-websites" = { + set_if = "$iis_check_sites$" + description = "Switch to use to check the health status of the local Sites" + } + "--check-apppools" = { + set_if = "$iis_check_apppools$" + description = "Switch to use to check the health status of the local Sites" } "--inv-level" = { value = "$iis_inventory_level$" - description = "Optional parameter to change the level of output. Default is 'normal', available options are 'normal','full'" + description = "Argument to change the level of output. Default is 'normal', available options are 'normal','full'" } "--inv-format" = { value = "$iis_inventory_format$" - description = "Optional parameter to provide output of the inventory in other formats, valid options are 'readable', 'i2conf' and 'json'" + description = "Argument to provide output of the inventory in other formats, valid options are 'readable', 'i2conf' and 'json'" } "--excluded-sites" = { value = "$iis_excluded_sites$" - description = "Optional: Excludes sites from checks and inventory. Provide multiple with spaces between" + description = "Excludes Sites from checks and inventory" } "--included-sites" = { value = "$iis_included_sites$" - description = "Optional: Includes sites to check while all other sites are excluded, affects both checks and inventory. Provide multiple with spaces between" + description = "Includes Sites to check while all other Sites are excluded, affects both checks and inventory" + } + "--stopped-sites" = { + value = "$iis_stopped_sites$" + description = "The specified Sites are checked that they are stopped" } "--warn-sites" = { value = "$iis_warn_sites$" - description = "Optional: These sites will return Warning if they are not in the expected state. Provide multiple with spaces between" + description = "These specified Sites will return Warning if they are not in the expected state" } - "--stopped-sites" = { - value = "$iis_stopped_sites$" - description = "Optional: These sites are checked that they are stopped. Provide multiple with spaces between" + "--perfcounter-sites" = { + set_if = "$iis_perfcounter_sites$" + description = "Switch to use to get perfcounters from Sites" } "--excluded-apppools" = { value = "$iis_excluded_apppools$" - description = "Optional: Excludes apppools from checks and inventory. Provide multiple with spaces between" + description = "Excludes AppPools from checks and inventory" } "--included-apppools" = { value = "$iis_included_apppools$" - description = "Optional: Includes apppools to check while all other apppools are excluded, affects both checks and inventory. Provide multiple with spaces between" - } - "--warn-apppools" = { - value = "$iis_warn_apppools$" - description = "Optional: These apppools will return Warning if they are not in the expected state. Provide multiple with spaces between" + description = "Includes AppPools to check while all other AppPools are excluded, affects both checks and inventory" } "--stopped-apppools" = { value = "$iis_stopped_apppools$" - description = "Optional: These apppools are checked that they are stopped. Provide multiple with spaces between" + description = "The specified AppPools are checked that they are stopped" } - "--perfcounter-sites" = { - set_if = "$iis_perfcounter_sites$" - description = "Parameter to use to get basic performance counters for the Sites" + "--warn-apppools" = { + value = "$iis_warn_apppools$" + description = "The specified AppPools will return Warning if they are not in the expected state" } "--perfcounter-apppools" = { set_if = "$iis_perfcounter_apppools$" - description = "Parameter to use to get basic performance counters for the AppPools" + description = "Switch to use to get perfcounters from AppPools" } - "--inv-running-only" = { - set_if = "$iis_inv_running_only$" - description = "Only inventory running Sites and/or AppPools, depending on what has been selected for inventory" + "--skip-empty-apppools" = { + set_if = "$iis_skip_empty_apppools$" + description = "Switch which sets do not check or inventory AppPools which are empty" } - "--inv-hide-empty" = { - set_if = "$inv_hide_empty_vars$" - description = "Optional parameter for inventory: Only print returned data that has values in them, skip empty arrays and vars." + "--hide-long-output" = { + set_if = "$iis_hide_long_output$" + description = "Switch to hide the long service output, only prints the summary output and any Sites or AppPools deviating from 'OK'" + } + "--expected-state" = { + set_if = "$iis_single_check$" + value = "$iis_expected_state$" + description = "Argument to provide the expected State of the AppPool or Site, used together with --single-check" } "--icinga2" = { set_if = "$iis_icinga2$" - description = "Used in the Icinga2 CommandDefinition, returns output and perfdata to the correct class. Do not use via command line." + description = "Switch used in the Icinga2 CommandDefinition, returns output and perfcounter to the correct class. Do not use via command line" } "--single-check" = { set_if = "$iis_single_check$" - description = "Used together with the Icinga2 Auto Apply rules, this is set when there is a single Site or AppPool to check. Do take great care if you use this outside of the auto apply rules." + description = "Switch used together with the Icinga2 Auto Apply rules, this is set when there is a single Site or AppPool to check. Do take great care if you use this outside of the auto apply rules" } - "--expected-state" = { - set_if = "$iis_single_check$" - value = "$iis_expected_state$" - description = "Optional: Parameter to provide the expected State of the AppPool or Site, used together with --single-check" + "--split-by" = { + value = "$iis_split_by$" + description = "Argument used to specify what splits all Sites and AppPool arguments. Default is a single space, ' '" + } + "--inv-hide-empty" = { + set_if = "$inv_hide_empty_vars$" + description = "Switch to hide empty vars from inventory output." + } + "--inv-running-only" = { + set_if = "$iis_inv_running_only$" + description = "Switch to only inventory running Sites and/or AppPools, depending on what has been selected for inventory" } "--verbose" = { set_if = "$iis_verbose$" - description = "Only inventory running Sites and/or AppPools, depending on what has been selected for inventory" + description = "Switch to use when trying to figure out why a service is not included, excluded or similarly when the returned output is not as expected" } } - vars.iis_check_apppools = false + vars.iis_inventory_sites = false + vars.iis_inventory_apppools = false vars.iis_check_sites = false - vars.iis_perfcounter_apppools = false + vars.iis_check_apppools = false + //vars.iis_inventory_level = "normal" + //vars.iis_inventory_format = "i2conf" + //vars.iis_excluded_sites = "" + //vars.iis_included_sites = "" + //vars.iis_stopped_sites = "" + //vars.iis_warn_sites = "" vars.iis_perfcounter_sites = false - vars.iis_inventory_apppools = false - vars.iis_inventory_sites = false - vars.iis_inv_running_only = false - vars.iis_inv_hide_empty_vars = false - vars.iis_icinga2 = false - vars.iis_verbose = false + //vars.iis_excluded_apppools = "" + //vars.iis_included_apppools = "" + //vars.iis_stopped_apppools = "" + //vars.iis_warn_apppools = "" + vars.iis_perfcounter_apppools = false + vars.iis_skip_empty_apppools = false + vars.iis_hide_long_output = false vars.iis_expected_state = "Started" + vars.iis_icinga2 = false vars.iis_single_check = false + vars.iis_split_by = false + vars.iis_inv_hide_empty_vars = false + vars.iis_inv_running_only = false + vars.iis_verbose = false } #### AppPool Monitoring -Monitor all AppPools, does not need any data from inventory. +Monitor all AppPools, does not need any data from inventory. It checks that all available AppPools are "Started" by default. apply Service "IIS AppPools"{ import "generic-service" check_command = "check_iis" - assign where host.name == NodeName - vars.iis_check_apppools = true - vars.iis_stopped_apppools = "" + assign where host.name == NodeName } -Monitor all AppPools, same as above, just added with perfcounter option. +Monitor all AppPools, same as above, just added with perfcounter option and excluded AppPools ".NET v2.0" and ".NET v4.5" apply Service "IIS AppPools"{ import "generic-service" @@ -360,7 +442,9 @@ Monitor all AppPools, same as above, just added with perfcounter option. vars.iis_check_apppools = true vars.iis_perfcounter_apppools = true - vars.iis_stopped_apppools = "" + vars.iis_excluded_apppools = ".NET v2.0,.NET v4.5" + vars.iis_split_by = "," + vars.iis_verbose = true } Monitors AppPools based on inventory data (stored in the host object), this specific apply rule only adds running apppools to monitoring, with perfcounters @@ -374,6 +458,7 @@ Monitors AppPools based on inventory data (stored in the host object), this spec vars.iis_check_apppools = true vars.iis_included_apppools = vars.Name vars.iis_perfcounter_apppools = true + vars.iis_split_by = "," assign where config.State == "Started" } @@ -389,10 +474,11 @@ Monitors AppPools based on inventory data (stored in the host object), this spec vars.iis_included_apppools = vars.Name vars.iis_stopped_apppools = vars.Name vars.iis_perfcounter_apppools = true + vars.iis_split_by = "," assign where config.State == "Stopped" } -Recommended method: Monitors AppPools based on inventory data (stored in the host object), this specific apply rule adds uses the state from inventory, with perfcounters +Recommended method: Monitors AppPools based on inventory data (stored in the host object), this specific apply rule adds uses the state from inventory, with perfcounters and hides long output apply Service "IIS AppPool " for (name => config in host.vars.inv.iis.apppool) { import "generic-service" @@ -405,6 +491,7 @@ Recommended method: Monitors AppPools based on inventory data (stored in the hos vars.iis_perfcounter_apppools = true vars.iis_expected_state = vars.State vars.iis_single_check = true + vars.iis_split_by = "," } @@ -417,13 +504,10 @@ Monitors all Sites, does not use inventory data. check_command = "check_iis" vars.iis_check_sites = true - vars.iis_perfcounter_sites = true - assign where host.name == NodeName - } -Monitors all Sites, does not use inventory data, the same as above, just added perfcounters. +Monitors all Sites, does not use inventory data, the same as above, just added perfcounters apply Service "IIS Sites"{ import "generic-service" @@ -433,7 +517,6 @@ Monitors all Sites, does not use inventory data, the same as above, just added p vars.iis_check_sites = true vars.iis_perfcounter_sites = true assign where host.name == NodeName - } Monitors Sites based on inventory data (stored in the host object), this specific apply rule only adds running sites to monitoring, with perfcounters @@ -462,6 +545,7 @@ Monitors Sites based on inventory data (stored in the host object), this specifi vars.iis_included_sites = vars.Name vars.iis_stopped_sites = vars.Name vars.iis_perfcounter_sites = true + vars.iis_split_by = "," assign where config.State == "Stopped" } @@ -477,6 +561,7 @@ Recommended method: Monitors Sites based on inventory data (stored in the host o vars.iis_included_sites = vars.Name vars.iis_perfcounter_sites = true vars.iis_expected_state = vars.State + vars.iis_split_by = "," vars.iis_single_check = true } diff --git a/Solution/check_iis/Program.cs b/Solution/check_iis/Program.cs index e22b05e..66a6385 100644 --- a/Solution/check_iis/Program.cs +++ b/Solution/check_iis/Program.cs @@ -107,19 +107,19 @@ private static int Main(string[] args) var p = GetP(); - p.Setup('a', "inventory-apppools") - .WithDescription("Switch to use to provide inventory of AppPools.") - .Callback(value => do_inventory_apppools = value); - - p.Setup('A', "inventory-websites") + p.Setup('a', "inventory-websites") .WithDescription("Switch to use to provide inventory of Sites") .Callback(value => do_inventory_sites = value); - p.Setup('B', "check-websites") + p.Setup('A', "inventory-apppools") + .WithDescription("Switch to use to provide inventory of AppPools") + .Callback(value => do_inventory_apppools = value); + + p.Setup('b', "check-websites") .WithDescription("Switch to use to check the health status of the local Sites") .Callback(value => do_sites = value); - p.Setup('C', "check-apppools") + p.Setup('B', "check-apppools") .WithDescription("Switch to use to check the health status of the local AppPools") .Callback(value => do_apppools = value); @@ -134,51 +134,51 @@ private static int Main(string[] args) .SetDefault("readable"); p.Setup>('F', "excluded-sites") - .WithDescription("Excludes Sites from checks and inventory. Provide multiple with spaces between") + .WithDescription("Excludes Sites from checks and inventory") .Callback(items => temp_excluded_sites = items); p.Setup>('G', "included-sites") - .WithDescription("Includes Sites to check while all other Sites are excluded, affects both checks and inventory. Provide multiple with spaces between") + .WithDescription("Includes Sites to check while all other Sites are excluded, affects both checks and inventory") .Callback(items => temp_included_sites = items); p.Setup>('h', "stopped-sites") - .WithDescription("\tThe specified Sites are checked that they are stopped. Provide multiple with spaces between") + .WithDescription("\tThe specified Sites are checked that they are stopped") .Callback(items => temp_stopped_sites = items); p.Setup>('H', "warn-sites") - .WithDescription("\tThese specified Sites will return Warning if they are not in the expected state. Provide multiple with spaces between") + .WithDescription("\tThese specified Sites will return Warning if they are not in the expected state") .Callback(items => temp_warn_sites = items); p.Setup('i', "perfcounter-sites") - .WithDescription("Switch to use to get perfcounters from local Sites") + .WithDescription("Switch to use to get perfcounters from Sites") .Callback(value => do_perfcounter_sites = value); p.Setup>('I', "excluded-apppools") - .WithDescription("Excludes AppPools from checks and inventory. Provide multiple with spaces between") + .WithDescription("Excludes AppPools from checks and inventory") .Callback(items => temp_excluded_apppools = items); p.Setup>('J', "included-apppools") - .WithDescription("Includes apppools to check while all other AppPools are excluded, affects both checks and inventory. Provide multiple with spaces between") + .WithDescription("Includes AppPools to check while all other AppPools are excluded, affects both checks and inventory") .Callback(items => temp_included_apppools = items); p.Setup>('k', "stopped-apppools") - .WithDescription("The specified AppPools are checked that they are stopped. Provide multiple with spaces between") + .WithDescription("The specified AppPools are checked that they are stopped") .Callback(items => temp_stopped_apppools = items); p.Setup>('K', "warn-apppools") - .WithDescription("\tThe specified AppPools will return Warning if they are not in the expected state. Provide multiple with spaces between") + .WithDescription("\tThe specified AppPools will return Warning if they are not in the expected state") .Callback(items => temp_warn_apppools = items); p.Setup('l', "perfcounter-apppools") - .WithDescription("Switch to use to get perfcounters from local AppPools") + .WithDescription("Switch to use to get perfcounters from AppPools") .Callback(value => do_perfcounter_apppools = value); p.Setup('L', "skip-empty-apppools") - .WithDescription("Switch which sets do not inventory AppPools which are empty or unused.") + .WithDescription("Switch which sets do not check or inventory AppPools which are empty") .Callback(value => do_skip_empty_apppools = value); p.Setup('T', "hide-long-output") - .WithDescription("Switch to hide the long service output, only prints the summary output and any Sites or Services deviating from 'OK'") + .WithDescription("Switch to hide the long service output, only prints the summary output and any Sites or AppPools deviating from 'OK'") .Callback(value => do_hide_long_output = value); p.Setup('u', "expected-state") @@ -190,15 +190,15 @@ private static int Main(string[] args) .Callback(value => do_i2 = value); p.Setup('W', "single-check") - .WithDescription("\tSwitch used together with the Icinga2 Auto Apply rules, this is set when there is a single Site or AppPool to check. Do take great care if you use this outside of the auto apply rules.") + .WithDescription("\tSwitch used together with the Icinga2 Auto Apply rules, this is set when there is a single Site or AppPool to check. Do take great care if you use this outside of the auto apply rules") .Callback(value => do_singluar_check = value); p.Setup('x', "split-by") - .WithDescription("\tArgument used to specify what splits all Sites and AppPool arguments. Default is a single space, ' '.") + .WithDescription("\tArgument used to specify what splits all Sites and AppPool arguments. Default is a single space, ' '") .Callback(value => split_by = value); p.Setup('X', "inv-hide-empty") - .WithDescription("Switch to hide empty vars from inventory output.") + .WithDescription("Switch to hide empty vars from inventory output") .Callback(value => do_skip_empty_vars = value); p.Setup('y', "inv-running-only") @@ -207,7 +207,7 @@ private static int Main(string[] args) p.Setup('z', "verbose") .Callback(value => do_verbose = value) - .WithDescription("\tSwitch to use when trying to figure out why a service is not included, excluded or similarly when the returned output is not as expected") + .WithDescription("\tSwitch to use when trying to figure out why a Site or an AppPool is not included, excluded or similarly when the returned output is not as expected") .SetDefault(false); p.Setup('Z', "debug") @@ -218,30 +218,32 @@ private static int Main(string[] args) p.SetupHelp("?", "help") .Callback(text => Console.WriteLine(text)) .UseForEmptyArgs() - .WithHeader(System.AppDomain.CurrentDomain.FriendlyName + " - Windows Service Status plugin for Icinga2, Icinga, Centreon, Shinken, Naemon and other nagios like systems.\n\tVersion: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); + .WithHeader(System.AppDomain.CurrentDomain.FriendlyName + " - Windows Service Status plugin for Icinga2, Icinga, Centreon, Shinken, Naemon and other nagios like systems\n\tVersion: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); var result = p.Parse(args); if ((do_apppools == false) && (do_inventory_apppools == false) && (do_inventory_sites == false) && (do_sites == false)) { // Not going to check Inventory or Checks, no parameters specified for it. + Console.WriteLine("Neither health check or inventory switches have been specified"); return (int)ServiceState.ServiceUnknown; } // Lets see which of the supplied switches changed anything in the include/exclude/stopped context - HandleArguments(temp_excluded_sites, temp_included_sites, temp_stopped_sites, temp_warn_sites, - temp_excluded_apppools, temp_included_apppools, temp_stopped_apppools, temp_warn_apppools, split_by); + HandleArguments(do_sites, do_apppools, do_inventory_sites, do_inventory_apppools, temp_excluded_sites, temp_included_sites, temp_stopped_sites, + temp_warn_sites, temp_excluded_apppools, temp_included_apppools, temp_stopped_apppools, temp_warn_apppools, split_by); // Inventory is blocked from running at the same time as other checks, thus it is run first if specified. if (do_inventory_apppools == true || do_inventory_sites == true) { - temp = IisInventory(do_sites, do_apppools, do_inventory_sites, do_inventory_apppools, inventory_format, inventory_level, do_all_running_only, do_skip_empty_vars, do_skip_empty_apppools); + temp = IisInventory(do_sites, do_apppools, do_inventory_sites, do_inventory_apppools, inventory_format, inventory_level, do_all_running_only, + do_skip_empty_vars, do_skip_empty_apppools); return temp; } if (do_apppools == true) { - returncode = CheckAllAppPools(returncode, do_perfcounter_apppools, do_singluar_check, expected_state); + returncode = CheckAllAppPools(returncode, do_perfcounter_apppools, do_singluar_check, expected_state, do_skip_empty_apppools); } if (do_sites == true) { @@ -276,8 +278,10 @@ private static string[] SplitList(List items, string split_by) } } - private static void HandleArguments(List temp_excluded_sites, List temp_included_sites, List temp_stopped_sites, List temp_warn_sites, - List temp_excluded_apppools, List temp_included_apppools, List temp_stopped_apppools, List temp_warn_apppools, string split_by) + private static void HandleArguments(bool do_sites, bool do_apppools, bool do_inventory_sites, bool do_inventory_apppools, + List temp_excluded_sites, List temp_included_sites, List temp_stopped_sites, List temp_warn_sites, + List temp_excluded_apppools, List temp_included_apppools, List temp_stopped_apppools, List temp_warn_apppools, + string split_by) { if (temp_excluded_sites.Count > 0) { @@ -327,60 +331,66 @@ private static void HandleArguments(List temp_excluded_sites, List config in host.vars.inv.iis.site) { +// import "generic-service" +// +// check_command = "check_iis" +// +// vars += config +// vars.iis_check_sites = true +// vars.iis_included_sites = vars.Name +// vars.iis_perfcounter_sites = true +// vars.iis_expected_state = vars.State +// vars.iis_split_by = "," +// vars.iis_single_check = true +//} + +// Monitoring Sites as a group +//apply Service "IIS Sites"{ +// import "generic-service" +// +// check_command = "check_iis" +// +// assign where host.name == NodeName +// +// vars.iis_check_sites = true +// vars.iis_perfcounter_sites = true +// vars.iis_verbose = true +//} + +// Monitoring Inventoried AppPools +//apply Service "IIS AppPool " for (name => config in host.vars.inv.iis.apppool) { +// import "generic-service" +// +// check_command = "check_iis" +// +// vars += config +// vars.iis_check_apppools = true +// vars.iis_included_apppools = vars.Name +// vars.iis_perfcounter_apppools = true +// vars.iis_expected_state = vars.State +// vars.iis_split_by = "," +// vars.iis_single_check = true +//} + +// Monitoring AppPools as a group +//apply Service "IIS AppPools"{ +// import "generic-service" +// +// check_command = "check_iis" +// +// assign where host.name == NodeName +// +// vars.iis_check_apppools = true +// vars.iis_perfcounter_apppools = true +// vars.iis_verbose = true +//} + +// Do not touch anything below this comment. +object CheckCommand "check_iis" { + import "plugin-check-command" + + command = [ PluginDir + "/check_iis.exe" ] + + arguments = { + "--inventory-websites" = { + set_if = "$iis_inventory_sites$" + description = "Switch to use to provide inventory of Sites" + } + "--inventory-apppools" = { + set_if = "$iis_inventory_apppools$" + description = "Switch to use to provide inventory of AppPools" + } + "--check-websites" = { + set_if = "$iis_check_sites$" + description = "Switch to use to check the health status of the local Sites" + } + "--check-apppools" = { + set_if = "$iis_check_apppools$" + description = "Switch to use to check the health status of the local Sites" + } + "--inv-level" = { + value = "$iis_inventory_level$" + description = "Argument to change the level of output. Default is 'normal', available options are 'normal','full'" + } + "--inv-format" = { + value = "$iis_inventory_format$" + description = "Argument to provide output of the inventory in other formats, valid options are 'readable', 'i2conf' and 'json'" + } + "--excluded-sites" = { + value = "$iis_excluded_sites$" + description = "Excludes Sites from checks and inventory" + } + "--included-sites" = { + value = "$iis_included_sites$" + description = "Includes Sites to check while all other Sites are excluded, affects both checks and inventory" + } + "--stopped-sites" = { + value = "$iis_stopped_sites$" + description = "The specified Sites are checked that they are stopped" + } + "--warn-sites" = { + value = "$iis_warn_sites$" + description = "These specified Sites will return Warning if they are not in the expected state" + } + "--perfcounter-sites" = { + set_if = "$iis_perfcounter_sites$" + description = "Switch to use to get perfcounters from Sites" + } + "--excluded-apppools" = { + value = "$iis_excluded_apppools$" + description = "Excludes AppPools from checks and inventory" + } + "--included-apppools" = { + value = "$iis_included_apppools$" + description = "Includes AppPools to check while all other AppPools are excluded, affects both checks and inventory" + } + "--stopped-apppools" = { + value = "$iis_stopped_apppools$" + description = "The specified AppPools are checked that they are stopped" + } + "--warn-apppools" = { + value = "$iis_warn_apppools$" + description = "The specified AppPools will return Warning if they are not in the expected state" + } + "--perfcounter-apppools" = { + set_if = "$iis_perfcounter_apppools$" + description = "Switch to use to get perfcounters from AppPools" + } + "--skip-empty-apppools" = { + set_if = "$iis_skip_empty_apppools$" + description = "Switch which sets do not check or inventory AppPools which are empty" + } + "--hide-long-output" = { + set_if = "$iis_hide_long_output$" + description = "Switch to hide the long service output, only prints the summary output and any Sites or AppPools deviating from 'OK'" + } + "--expected-state" = { + set_if = "$iis_single_check$" + value = "$iis_expected_state$" + description = "Argument to provide the expected State of the AppPool or Site, used together with --single-check" + } + "--icinga2" = { + set_if = "$iis_icinga2$" + description = "Switch used in the Icinga2 CommandDefinition, returns output and perfcounter to the correct class. Do not use via command line" + } + "--single-check" = { + set_if = "$iis_single_check$" + description = "Switch used together with the Icinga2 Auto Apply rules, this is set when there is a single Site or AppPool to check. Do take great care if you use this outside of the auto apply rules" + } + "--split-by" = { + value = "$iis_split_by$" + description = "Argument used to specify what splits all Sites and AppPool arguments. Default is a single space, ' '" + } + "--inv-hide-empty" = { + set_if = "$inv_hide_empty_vars$" + description = "Switch to hide empty vars from inventory output." + } + "--inv-running-only" = { + set_if = "$iis_inv_running_only$" + description = "Switch to only inventory running Sites and/or AppPools, depending on what has been selected for inventory" + } + "--verbose" = { + set_if = "$iis_verbose$" + description = "Switch to use when trying to figure out why a service is not included, excluded or similarly when the returned output is not as expected" + } + } + vars.iis_inventory_sites = false + vars.iis_inventory_apppools = false + vars.iis_check_sites = false + vars.iis_check_apppools = false + //vars.iis_inventory_level = "normal" + //vars.iis_inventory_format = "i2conf" + //vars.iis_excluded_sites = "" + //vars.iis_included_sites = "" + //vars.iis_stopped_sites = "" + //vars.iis_warn_sites = "" + vars.iis_perfcounter_sites = false + //vars.iis_excluded_apppools = "" + //vars.iis_included_apppools = "" + //vars.iis_stopped_apppools = "" + //vars.iis_warn_apppools = "" + vars.iis_perfcounter_apppools = false + vars.iis_skip_empty_apppools = false + vars.iis_hide_long_output = false + vars.iis_expected_state = "Started" + vars.iis_icinga2 = false + vars.iis_single_check = false + vars.iis_split_by = false + vars.iis_inv_hide_empty_vars = false + vars.iis_inv_running_only = false + vars.iis_verbose = false + +} \ No newline at end of file