Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-IcingaCheckCommandConfig: move -C from every single command to template #631

Merged
merged 1 commit into from
Mar 12, 2024
Merged

Conversation

Al2Klimov
Copy link
Member

@Al2Klimov Al2Klimov commented Jun 2, 2023

@cla-bot cla-bot bot added the cla/signed label Jun 2, 2023
@Al2Klimov Al2Klimov marked this pull request as draft June 6, 2023 11:42
@Al2Klimov
Copy link
Member Author

@LordHepipud Before testing: does the code change look good?

@Al2Klimov Al2Klimov marked this pull request as ready for review July 25, 2023 13:24
@LordHepipud
Copy link
Collaborator

Looks good so far. We should test both, Director baskets and plain Icinga conf to ensure there is no bug remaining.
But the change looks promising

@Al2Klimov
Copy link
Member Author

Walked through Icinga/icinga2#9062 (comment), but didn't enable IfW API (which doesn't use -C). Also manipulated the changed file on disk just as here to get a basket with only one "-C" and renamed the imported command (just for fun). Works:

Executed Command 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' '-NoProfile' '-NoLogo' '-ExecutionPolicy' 'ByPass' '-C' 'try { Use-Icinga -Minimal; } catch { Write-Output '\''The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details'\''; Write-Output '\''Error:'\'' $($_.Exception.Message)Components:rn$( Get-Module -ListAvailable '\''icinga-powershell-*'\'' )rn'\''Module-Path:'\''rn$($Env:PSModulePath); exit 3; }; Exit-IcingaExecutePlugin -Command '\''Invoke-IcingaCheckCPU'\'' '

@Al2Klimov
Copy link
Member Author

Plain config looks promising as well:

object CheckCommand "PowerShell Base" {
    import "plugin-check-command"
    command = [
        "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
    ]
    timeout = 3m
    arguments += {
        "-C" = {
            order = 0
            value = "try { Use-Icinga -Minimal; } catch { Write-Output 'The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details'; Write-Output 'Error:' $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable 'icinga-powershell-*' )`r`n'Module-Path:'`r`n$$($$Env:PSModulePath); exit 3; }; Exit-IcingaExecutePlugin -Command '$ifw_api_command$' "
        }
        "-ExecutionPolicy" = {
            order = -1
            value = "$IcingaPowerShellBase_String_ExecutionPolicy$"
        }
...

@Al2Klimov
Copy link
Member Author

Placed the latter in /etc/icinga2/zones.d/global-templates/PSb.conf, renamed PS Base in Director not to collide and fixed import in CPU command. Still works.

Object 'LOLCAT-IcingaCheckCPU' of type 'CheckCommand':
  % declared in '/var/lib/icinga2/api/packages/director/c35b7b43-cd1d-4ff1-b40a-f584a2a729d3/zones.d/director-global/commands.conf', lines 4276:1-4276:43
  * __name = "LOLCAT-IcingaCheckCPU"
  * arguments
    % = modified in '/etc/icinga2/zones.d/global-templates/PSb.conf', lines 7:5-24:5
    % = modified in '/var/lib/icinga2/api/packages/director/c35b7b43-cd1d-4ff1-b40a-f584a2a729d3/zones.d/director-global/commands.conf', lines 4279:5-4336:5
    * -C
      * order = 0
      * value = "try { Use-Icinga -Minimal; } catch { Write-Output 'The Icinga PowerShell Framework is either not installed on the system or not configured properly. Please check https://icinga.com/docs/windows for further details'; Write-Output 'Error:' $$($$_.Exception.Message)Components:`r`n$$( Get-Module -ListAvailable 'icinga-powershell-*' )`r`n'Module-Path:'`r`n$$($$Env:PSModulePath); exit 3; }; Exit-IcingaExecutePlugin -Command '$ifw_api_command$' "
    * -Core
      * order = 4
      * set_if
        * arguments = [ ]
        * deprecated = false
        * name = "<anonymous>"
        * side_effect_free = false
        * type = "Function"
      * value
        * arguments = [ ]
        * deprecated = false
        * name = "<anonymous>"
        * side_effect_free = false
        * type = "Function"
    * -Critical
      * order = 3
      * value = "$IcingaCheckCPU_Object_Critical$"
    * -ExecutionPolicy
      * order = -1
      * value = "$IcingaPowerShellBase_String_ExecutionPolicy$"
    * -NoLogo
      * order = -2
      * set_if = "1"
    * -NoPerfData
      * order = 99
      * set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
    * -NoProfile
      * order = -3
      * set_if = "1"
    * -ThresholdInterval
      * order = 100
      * set_if
        * arguments = [ ]
        * deprecated = false
        * name = "<anonymous>"
        * side_effect_free = false
        * type = "Function"
      * value
        * arguments = [ ]
        * deprecated = false
        * name = "<anonymous>"
        * side_effect_free = false
        * type = "Function"
    * -Verbosity
      * order = 5
      * value = "$IcingaCheckCPU_Int32_Verbosity$"
    * -Warning
      * order = 2
      * value = "$IcingaCheckCPU_Object_Warning$"
  * command = [ "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" ]
    % = modified in '/etc/icinga2/zones.d/global-templates/PSb.conf', lines 3:5-5:5
  * env = null
  * execute
    % = modified in 'methods-itl.conf', lines 19:3-19:23
    % = modified in 'methods-itl.conf', lines 19:3-19:23
    % = modified in 'methods-itl.conf', lines 19:3-19:23
    * arguments = [ "checkable", "cr", "resolvedMacros", "useResolvedMacros" ]
    * deprecated = false
    * name = "Internal#PluginCheck"
    * side_effect_free = false
    * type = "Function"
  * name = "LOLCAT-IcingaCheckCPU"
  * package = "director"
  * source_location
    * first_column = 1
    * first_line = 4276
    * last_column = 43
    * last_line = 4276
    * path = "/var/lib/icinga2/api/packages/director/c35b7b43-cd1d-4ff1-b40a-f584a2a729d3/zones.d/director-global/commands.conf"
  * templates = [ "LOLCAT-IcingaCheckCPU", "plugin-check-command", "PowerShell Base", "plugin-check-command", "plugin-check-command" ]
    % = modified in '/var/lib/icinga2/api/packages/director/c35b7b43-cd1d-4ff1-b40a-f584a2a729d3/zones.d/director-global/commands.conf', lines 4276:1-4276:43
    % = modified in 'methods-itl.conf', lines 18:2-18:94
    % = modified in '/etc/icinga2/zones.d/global-templates/PSb.conf', lines 1:0-1:36
    % = modified in 'methods-itl.conf', lines 18:2-18:94
    % = modified in 'methods-itl.conf', lines 18:2-18:94
  * timeout = 180
    % = modified in '/etc/icinga2/zones.d/global-templates/PSb.conf', lines 6:5-6:16
  * type = "CheckCommand"
  * vars
    * IcingaCheckCPU_Switchparameter_NoPerfData = false
      % = modified in '/var/lib/icinga2/api/packages/director/c35b7b43-cd1d-4ff1-b40a-f584a2a729d3/zones.d/director-global/commands.conf', lines 4337:5-4337:58
    * IcingaPowerShellBase_String_ExecutionPolicy = "ByPass"
      % = modified in '/etc/icinga2/zones.d/global-templates/PSb.conf', lines 25:5-25:63
    * ifw_api_arguments
      % = modified in '/var/lib/icinga2/api/packages/director/c35b7b43-cd1d-4ff1-b40a-f584a2a729d3/zones.d/director-global/commands.conf', lines 4338:5-4357:5
      * Core
        * value = "$IcingaCheckCPU_String_Core$"
      * Critical
        * value = "$IcingaCheckCPU_Object_Critical$"
      * NoPerfData
        * set_if = "$IcingaCheckCPU_Switchparameter_NoPerfData$"
      * ThresholdInterval
        * value = "$IcingaCheckCPU_String_ThresholdInterval$"
      * Verbosity
        * value = "$IcingaCheckCPU_Int32_Verbosity$"
      * Warning
        * value = "$IcingaCheckCPU_Object_Warning$"
    * ifw_api_command = "Invoke-IcingaCheckCPU"
      % = modified in '/var/lib/icinga2/api/packages/director/c35b7b43-cd1d-4ff1-b40a-f584a2a729d3/zones.d/director-global/commands.conf', lines 4358:5-4358:50
  * zone = "director-global"

@Al2Klimov
Copy link
Member Author

@LordHepipud LordHepipud added this to the v1.12.0 milestone Mar 4, 2024
@Al2Klimov
Copy link
Member Author

Rebased, added change log.

@LordHepipud LordHepipud merged commit c7eeab8 into Icinga:master Mar 12, 2024
1 check passed
@LordHepipud
Copy link
Collaborator

Thanks!

@Al2Klimov Al2Klimov deleted the central-C branch March 12, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Director basket: consider centralising -C via command name CV
2 participants