This for Check_MK downtime bash script from command line
#Set downtime for check_mk hosts
#Powershell -noprofile -executionpolicy bypass -file .\set_downtime_check_mk.ps1 ##Cmd to run script
#create file servername.txt and write all the hostname that need to set downtime
param(
[Parameter(Mandatory=$true,HelpMessage="Number of minutes for downtime",Position=2)]
$Duration,
[string]$NagiosURL="http://example.com/checkmk/check_mk/view.py"
)
$Comment = "Powereshell+Automated+Downtime"
$Servers = Get-Content -Path servername.txt
$i = 0
Foreach($Server in $Servers){
#These are needed attributes for issuing the commands, but they don't actually show up anywhere else.
$NagiosCommand= "?_do_confirm=Yes&_do_actions=yes&_transid=-1&view_name=hoststatus&site=&_ack_sticky=on&_ack_otify=off&output_format=JSON&_username=<username>&_secret=<token>&_down_comment=$Comment&_down_from_now=From+now+for&_down_minutes=$Duration&host=$Server"
$Uri = "$NagiosURL$NagiosCommand"
$i = $i +1
$request = Invoke-WebRequest -Uri $Uri
#Determine if the command executed properly
$Success = Select-String -InputObject $request.Content -Pattern "MESSAGE: Successfully sent 1 commands" -SimpleMatch
if($Success){
Write-Host "$i)Passed: $Server Downtime command successfully submitted" -ForegroundColor Green
}else{
Write-Host "$i)Failed: $Server Downtime command Failed" -ForegroundColor Red
}
}
#Set downtime for check_mk hosts
#Powershell -noprofile -executionpolicy bypass -file .\set_downtime_check_mk.ps1 ##Cmd to run script
#create file servername.txt and write all the hostname that need to set downtime
param(
[Parameter(Mandatory=$true,HelpMessage="Number of minutes for downtime",Position=2)]
$Duration,
[string]$NagiosURL="http://example.com/checkmk/check_mk/view.py"
)
$Comment = "Powereshell+Automated+Downtime"
$Servers = Get-Content -Path servername.txt
$i = 0
Foreach($Server in $Servers){
#These are needed attributes for issuing the commands, but they don't actually show up anywhere else.
$NagiosCommand= "?_do_confirm=Yes&_do_actions=yes&_transid=-1&view_name=hoststatus&site=&_ack_sticky=on&_ack_otify=off&output_format=JSON&_username=<username>&_secret=<token>&_down_comment=$Comment&_down_from_now=From+now+for&_down_minutes=$Duration&host=$Server"
$Uri = "$NagiosURL$NagiosCommand"
$i = $i +1
$request = Invoke-WebRequest -Uri $Uri
#Determine if the command executed properly
$Success = Select-String -InputObject $request.Content -Pattern "MESSAGE: Successfully sent 1 commands" -SimpleMatch
if($Success){
Write-Host "$i)Passed: $Server Downtime command successfully submitted" -ForegroundColor Green
}else{
Write-Host "$i)Failed: $Server Downtime command Failed" -ForegroundColor Red
}
}
No comments:
Post a Comment