object Zone "global-templates" { global = true }
object CheckCommand "powershell" { import "plugin-check-command" timeout = 5m command = [ "powershell.exe" ] arguments = { "-command" = { skip_key = true value = "$ps_command$" order = 0 } "-args" = { skip_key = true value = "$ps_args$" order = 1 } } }
// 64 powershell object CheckCommand "powershell64" { import "plugin-check-command" timeout = 3m command = [ "C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe" ] arguments = { "-command" = { value = "$ps_command$" order = 0 } "-args" = { skip_key = true value = "$ps_args$" order = 1 } } } // powershell . object CheckCommand "powershell-bypass" { import "plugin-check-command" timeout = 3m command = [ "powershell.exe" ] arguments = { "-ExecutionPolicy" = { value = "ByPass" order = 0 } "-File" = { value = "$ps_command$" order = 1 } "-args" = { skip_key = true value = "$ps_args$" order = 2 } } }
apply Service "upd-powershell-scripts" { max_check_attempts = 2 // 60 check_interval = 60m retry_interval = 30m // Windows assign where host.vars.os == "Windows" && host.name == NodeName // Linux ignore where host.vars.os == "Linux" check_command = "powershell" vars.ps_command = "C:\\Scripts\\Icinga2\\update_icinga2_scripts.ps1" }
<# icinga2scripts Version 0.2 Description: Update powershell from remote host. Pavel Satin (c) 2016 pslater.ru@gmail.com #> $returnStateOK = 0 $returnStateWarning = 1 $returnStateCritical = 2 $returnStateUnknown = 3 $localDir = "c:\Scripts\icinga2\" $ScriptHost = "http://--" $ScriptHostPath = $ScriptHost + "/icinga2scripts/" Try { $HttpContent = Invoke-WebRequest -URI $ScriptHostPath -UseBasicParsing $ArrLinks = $HttpContent.Links | Foreach {$_.href } Foreach ($ArrStr in $ArrLinks) { if ( $ArrStr.endsWith(".ps1") ) { ## Apache2 $NewScriptHostPath = $ScriptHostPath + $ArrStr ## IIS, #$NewScriptHostPath = $ScriptHost + $ArrStr $localFile = $localDir + $ArrStr Invoke-WebRequest -URI $NewScriptHostPath -UseBasicParsing -OutFile $localFile $script_count = $script_count + 1 } } $icinga2_status = "Update OK: Downloads " + $script_count + " scripts." Write-Host $icinga2_status [System.Environment]::Exit($returnStateOK) } Catch { $ErrorMessage = $_.Exception.Message $FailedItem = $_.Exception.ItemName Write-Host $ErrorMessage [System.Environment]::Exit($returnStateCritical) }
icinga2 node update-config service icinga2 reload
apply Service "reboot-system" { // enable_active_checks = false max_check_attempts = 2 // Windows assign where host.vars.os == "Windows" && host.name == NodeName // Linux ignore where host.vars.os == "Linux" check_command = "powershell" vars.ps_command = "C:\\Scripts\\Icinga2\\Reboot_System.ps1" }
icinga2 node update-config service icinga2 reload
<# icinga2scripts Version 0.2 Description: Reboot system. Pavel Satin (c) 2016 pslater.ru@gmail.com #> $returnStateOK = 0 $returnStateWarning = 1 $returnStateCritical = 2 $returnStateUnknown = 3 # if ( $args[0] -ne $Null) { $ComputerName = $args[0] } else { $ComputerName = "localhost" } $result = Test-Connection -ComputerName $ComputerName -Count 2 -Quiet if ($result) { Restart-Computer -computername $ComputerName -force Write-Host "OK - Command send." [System.Environment]::Exit($returnStateOK) } #End if test-connection result else { Write-Host " $ComputerName ." [System.Environment]::Exit($returnStateUnknown) }
/bin/echo "[`date +%s`] SCHEDULE_FORCED_SVC_CHECK;;reboot-system;`date +%s`" >> /var/run/icinga2/cmd/icinga2.cmd
$returnStateOK = 0 $returnStateWarning = 1 $returnStateCritical = 2 $returnStateUnknown = 3
Write-Host " $ComputerName ." [System.Environment]::Exit($returnStateCritical)
Write-Host "OK - :" "<table><thead><tr><th>_</th><th>Value</th></tr></thead><tbody>" "<tr><td> :</td><td>" + $catridge_usage_prc + " %</td></tr>" "<tr><td> :</td><td>" + $page_count + "</td></tr></tbody></table>" "|catridge_usage_prc=$catridge_usage_prc;10;3;100;0" "|page_count=$page_count;;;;" [System.Environment]::Exit($returnStateOK)
'label'=value[UOM];[warn];[crit];[min];[max]
We raise micromonitoring on icinga2 with minimal costs
Repository with scripts
Monitoring plugins guidelines
Source: https://habr.com/ru/post/307560/
All Articles