Hello there,
maybe I'm right here. I've written a small application, which communicates with a ZABBIX server on version 6.0 by using
C# in .NET core 8 with JSON.
This includes to list all stored hosts, creating a maintenance and updating a maintenance.
Unlike the last one everything works fine. And this is the point, where I'm now out of ideas what to do.
Based on the API documentation => https://www.zabbix.com/documentation...tenance/update
I need the property timeperiods to say when an active maintenance shall be terminated earlier or later, however, ZABBIX reports:
So, I'm getting the information, that the given request with timeperiods as property won't work. When I'm running the JSON pattern without this property, then the command returns the expected result, like:
but the active maintenance is still running until the defined timestamp has been reached.
The skeleton for maintenance.update in C# looks like this:
I'm using this class pattern above here:
So, the JSON format for maintenance.update looks like this:
Do I miss something? Is there maybe an another way to handle this?
Thanks in advise. (:
Greetings
maybe I'm right here. I've written a small application, which communicates with a ZABBIX server on version 6.0 by using
C# in .NET core 8 with JSON.
This includes to list all stored hosts, creating a maintenance and updating a maintenance.
Unlike the last one everything works fine. And this is the point, where I'm now out of ideas what to do.
Based on the API documentation => https://www.zabbix.com/documentation...tenance/update
I need the property timeperiods to say when an active maintenance shall be terminated earlier or later, however, ZABBIX reports:
Code:
{
"jsonrpc": "2.0",
"error": {
"code": -32600,
"message": "Invalid request.",
"data": "Invalid parameter \"/\": unexpected parameter \"timeperiods\"."
}
"id": 3
}
So, I'm getting the information, that the given request with timeperiods as property won't work. When I'm running the JSON pattern without this property, then the command returns the expected result, like:
Code:
{
"jsonrpc": "2.0",
"result": {
"maintenanceids": [
"12"
]
},
"id": 1
}
The skeleton for maintenance.update in C# looks like this:
Code:
public class MaintenanceUpdate {
public String? jsonrpc;
public String? method;
public Parameters? @params;
public TimePeriod? timeperiods; // This might be wrong for the API?
public String? auth;
public double id;
public class Parameters {
public String? maintenanceid;
public List<HostSettings>? hosts;
}
public class HostSettings {
public String? hostid;
}
public class TimePeriod {
public int period;
public int timeperiod_type;
public uint start_date;
public int start_time;
public int every;
public int dayofweek;
public int day;
public int month;
}
}
}
Code:
using(StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream())) {
MaintenanceUpdate mUpdate = new MaintenanceUpdate() {
jsonrpc = "2.0",
method = "maintenance.update",
id = 3,
auth = < top secret key here :-) >,
@params = new MaintenanceUpdate.Parameters() {
maintenanceid = hostToUse.maintenanceid,
hosts = new List<MaintenanceUpdate.HostSettings>() {
new MaintenanceUpdate.HostSettings() {
hostid = hostID.ToString()
}
}
},
timeperiods = new MaintenanceUpdate.TimePeriod() {
period = 0
}
};
sw.Write(JsonConvert.SerializeObject(mUpdate));
}
MaintenanceUpdateResponse? responseMaintenanceUpdate;
httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using(StreamReader sr = new StreamReader(httpResponse.GetResponseStream())) {
String result = sr.ReadToEnd();
Console.WriteLine(result); // <-- prints the error message [...]unexpected parameter \"timeperiods\"."[...]
responseMaintenanceUpdate = JsonConvert.DeserializeObject<MaintenanceUpdateResponse>(result);
}
Code:
{
"jsonrpc": "2.0",
"method": "maintenance.update",
"params": {
"maintenanceid": "12",
"hosts": [
{
"hostid": "< ID of the host >"
}
]
},
"timeperiods": {
"period": 0,
"timeperiod_type": 0,
"start_date": 0,
"start_time": 0,
"every": 0,
"dayofweek": 0,
"day": 0,
"month": 0
},
"auth": "< super secret key :-) >",
"id": 3
}
Thanks in advise. (:
Greetings
Comment