Coder Social home page Coder Social logo

zabbix.api.core's Introduction

Build Status

Zabbix.NET.Core

Zabbix.NET.Core is a Zabbix API library based on .NET Standard 1.6.1. 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.

Install Package

Package is available on NuGet. Use this command PM> Install-Package Zabbix.API.Core

Configuration

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().

Usage examples

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 = "[email protected]",
            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 = "[email protected]",
            active = 0,
            severity = 63,
            period = "1-7,00:00-24:00"
        }
    }
});

createUserResponseJson.Wait();
Console.WriteLine(createUserResponseJson.Result);
zabbix.LogoutAsync().Wait();

License

MIT

zabbix.api.core's People

Contributors

aslabicki avatar 2m0nd avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.