Zabbix.NET.Core is a Zabbix API library based on .NET Standard 2.0. Fully asynchronous. Using this API you can very easy transform request and response into dynamic objects. You don't need to create special models. This library works with .NET Core applications.
Package is available on NuGet. Use this command PM> Install-Package Zabbix.API.Core
Initialize Zabbix object passing user login, password and url.
Zabbix zabbix = new Zabbix("admin", "zabbix", "http://zabbix.example/api_jsonrpc.php");
If it's needed use basic authentication.
Zabbix zabbix = new Zabbix("admin", "zabbix", "http://zabbix.example/api_jsonrpc.php", true);
Before call any request use LoginAsync() method. After all use LogoutAsync().
Create new user
Zabbix zabbix = new Zabbix("admin", "zabbix", "http://zabbix.example/api_jsonrpc.php");
zabbix.LoginAsync().Wait();
Task<Response> createUserResponse = zabbix.GetResponseObjectAsync("user.create", new
{
alias = "joe.kowalsky",
passwd = "password",
name = "Joe",
surname = "Kowalsky",
autologin = 1,
autologout = 0,
type = 2,
usrgrps = new[]
{
new
{
usrgrpid = 7
}
},
user_medias = new[]
{
new
{
mediatypeid = 1,
sendto = "joe.kowalsky@example.com",
active = 0,
severity = 63,
period = "1-7,00:00-24:00"
}
}
});
if (createUserResponse.Result.error != null)
{
var error = createUserResponse.Result.error;
Console.WriteLine(error.GetErrorMessage());
}
else
{
userid = createUserResponse.Result.result.userids[0];
Console.WriteLine(userid);
}
createUserResponse.Wait();
zabbix.LogoutAsync().Wait();
Check user exist
Zabbix zabbix = new Zabbix("admin", "zabbix", "http://zabbix.example/api_jsonrpc.php");
zabbix.LoginAsync().Wait();
Task<Response> checkUserExistResponse = zabbix.GetResponseObjectAsync("user.get", new
{
output = "userid",
filter = new { userid = 32 }
});
if (checkUserExistResponse.Result.result.Count > 0)
{
Console.WriteLine($"User id {userid} exist");
}
else
{
Console.WriteLine($"User id {userid} not exist");
}
checkUserExistResponse.Wait();
zabbix.LogoutAsync().Wait();
You can get json string using GetResponseJsonAsync() method.
Zabbix zabbix = new Zabbix("admin", "zabbix", "http://zabbix.example/api_jsonrpc.php");
zabbix.LoginAsync().Wait();
Task<string> createUserResponseJson = zabbix.GetResponseJsonAsync("user.create", new
{
alias = "david.kowalsky",
passwd = "password",
name = "David",
surname = "Kowalsky",
autologin = 1,
autologout = 0,
type = 2,
usrgrps = new[]
{
new
{
usrgrpid = 7
}
},
user_medias = new[]
{
new
{
mediatypeid = 1,
sendto = "david.kowalsky@example.com",
active = 0,
severity = 63,
period = "1-7,00:00-24:00"
}
}
});
createUserResponseJson.Wait();
Console.WriteLine(createUserResponseJson.Result);
zabbix.LogoutAsync().Wait();
MIT