Hi Team,
I am unable to create maintenance via rest api, I get the following error, Below is the code for Creating maintenance with powershell
================================================== ======
# Login to Zabbix
function global:Zabbix-Login {
param ($zabbixApiURL, $zLogin, $zPassword)
$body = @{
method = "user.login"
jsonrpc = "2.0"
id = 1
auth = $null
params = @{
user = $zLogin
password = $zPassword
}
}
$global:zabSession = Invoke-RestMethod $zabbixApiURL -ContentType "application/json" -Body ($body | ConvertTo-Json) -Method Post |
Select-Object jsonrpc,@{Name = "session"; Expression = {$_.Result}}, id, @{Name = "URL"; Expression ={$zabbixApiURL}}, @{Name = "error"; Expression = {$_.error}}
if ($zabsession.session) {
$global:zabSessionParams=@{jsonrpc=$zabsession.jso nrpc;session=$zabsession.session;id=$zabsession.id ;url=$zabsession.URL}
Write-Host "`nConnected to $zabbixApiURL."
}
else {
If ($zabsession.error) {
Write-Error $zabsession.error
Exit -1
}
Else {
Write-Error "Authentication token is NULL"
Write-Error $zabsession
Exit -1
}
}
}
# Create Maintenance With Servername
function global:Zabbix-CreateMaintenance {
#param ($MaintenanceName)
$body = @{
"method" = "maintenance.create"
"jsonrpc" = $zabSessionParams.jsonrpc
"id" = ++$zabSessionParams.id
"auth" = $zabSessionParams.session
"params" = @{
name = "ServerMaintenance"
active_since = 1358844540
active_till = 1390466940
hostids = 10254
timeperiods = @{
timeperiod_type = 3
every = 1
dayofweek = 64
start_time = 64800
period = 3600
}
}
}
$respond = Invoke-RestMethod $zabSessionParams.url -ContentType "application/json" -Body ($body | ConvertTo-Json) -Method Post
If ($respond.error) {
Write-Error "Unable to Create Maintenance for $MaintenanceName"
Write-Error $respond.error
Exit -1
}
Else {
Write-Host "$respond.result"
}
}
==============================================
Below is the error which I receive,
Zabbix-CreateMaintenance : Unable to Create Maintenance for ServerMaintenance
At C:\Octopus\Work\20180724113916-696-29\Script.ps1:39 char:5
+ Zabbix-CreateMaintenance
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (
[Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException, Zabbix-CreateMaintenance
Requesting anyone to assist on thiis.
thanks.
I am unable to create maintenance via rest api, I get the following error, Below is the code for Creating maintenance with powershell
================================================== ======
# Login to Zabbix
function global:Zabbix-Login {
param ($zabbixApiURL, $zLogin, $zPassword)
$body = @{
method = "user.login"
jsonrpc = "2.0"
id = 1
auth = $null
params = @{
user = $zLogin
password = $zPassword
}
}
$global:zabSession = Invoke-RestMethod $zabbixApiURL -ContentType "application/json" -Body ($body | ConvertTo-Json) -Method Post |
Select-Object jsonrpc,@{Name = "session"; Expression = {$_.Result}}, id, @{Name = "URL"; Expression ={$zabbixApiURL}}, @{Name = "error"; Expression = {$_.error}}
if ($zabsession.session) {
$global:zabSessionParams=@{jsonrpc=$zabsession.jso nrpc;session=$zabsession.session;id=$zabsession.id ;url=$zabsession.URL}
Write-Host "`nConnected to $zabbixApiURL."
}
else {
If ($zabsession.error) {
Write-Error $zabsession.error
Exit -1
}
Else {
Write-Error "Authentication token is NULL"
Write-Error $zabsession
Exit -1
}
}
}
# Create Maintenance With Servername
function global:Zabbix-CreateMaintenance {
#param ($MaintenanceName)
$body = @{
"method" = "maintenance.create"
"jsonrpc" = $zabSessionParams.jsonrpc
"id" = ++$zabSessionParams.id
"auth" = $zabSessionParams.session
"params" = @{
name = "ServerMaintenance"
active_since = 1358844540
active_till = 1390466940
hostids = 10254
timeperiods = @{
timeperiod_type = 3
every = 1
dayofweek = 64
start_time = 64800
period = 3600
}
}
}
$respond = Invoke-RestMethod $zabSessionParams.url -ContentType "application/json" -Body ($body | ConvertTo-Json) -Method Post
If ($respond.error) {
Write-Error "Unable to Create Maintenance for $MaintenanceName"
Write-Error $respond.error
Exit -1
}
Else {
Write-Host "$respond.result"
}
}
==============================================
Below is the error which I receive,
Zabbix-CreateMaintenance : Unable to Create Maintenance for ServerMaintenance
At C:\Octopus\Work\20180724113916-696-29\Script.ps1:39 char:5
+ Zabbix-CreateMaintenance
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (
[Write-Error], WriteErrorException+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException, Zabbix-CreateMaintenance
Requesting anyone to assist on thiis.
thanks.