Giter Club home page Giter Club logo

zabbix-6.0-api's Introduction

Zabbix 6.0 API Library for C#

This is a C# library designed to simplify interactions with the Zabbix API (version 6.0). It provides an intuitive way to perform operations (synchronously and asynchronously) such as creating, updating, deleting and getting entties for Zabbix.

Still in Development

Please note that this library is still under active development.

Installation

Currently, the library can be used by either cloning this repository or by installing the NuGet package https://www.nuget.org/packages/Zabbix.Api.NET/

Usage

First, let's establish a connection to the Zabbix server using your credentials:

string url = "http://ZABBIX_SERVER/api_jsonrpc.php";
string username = "Admin";
string password = "zabbix";

ZabbixCore core = new ZabbixCore(url, username, password);

Creating Entities

Creating an Entity returns its remote Zabbix id, Zabbix will set every unset value to its default value.
It's important to note that each entity has a set of required properties that must be configured, as indicated by the constructor.

Host serverHost = new Host("Server", new List<HostGroup>() { linuxServers });
string createdServerHostId = core.Hosts.Create(serverHost);

Updating Entities

Updating an entity also returns its Zabbix ID. During the update process, only the properties that are explicitly set (not null) will be sent to Zabbix.

serverHost.Status = 1;
string updatedServerHostId = core.Hosts.Update(serverHost);

Deleting Entities

Deleting a Entity returns its former remote Zabbix id.
When deleting a Entity you need to know the remote Zabbix id.

//By Entity
string updatedServerHostId = core.Hosts.Delete(serverHost);

//Or also by Id
string updatedServerHostId = core.Hosts.Delete(createdServerHostId);

Getting Entities

This is a simple Get, it will return every Host that is configured on Zabbix.

List<Host> hosts = core.Hosts.Get().ToList();

This will return the amount of configured Hosts on Zabbix:

int hostAmount = core.Hosts.CountOutput();

This is will return every Host that is configured on Zabbix as a Dictionary where their Id is the Key.

Dictionary<string, Host> hosts = core.Hosts.PreserveKeys();

However, the Get, CountOutput and PreserveKeys method can also accept a FilterOptions object as its parameter. Every entity has its own FilterOptions object named EntitynameFilterOptions.
The FilterOptions can be initialized directly via the constructor like so:

var hosts = core.Hosts.Get(new()
{
	HostIds = new List<string>(){"12312","32323"}
});

Every query (every FilterOption Prop that has a 'Select' in its name) can be used in multiple ways:

The Default Constructor will set it to "extend"

var hosts = core.Hosts.Get(new()
{
	SelectItems = new()
});

Return every Host and its Items but with only their 'Delay', 'Hostid' and 'ItemId' property set

var hosts = core.Hosts.Get(new()
{
	SelectItems = new("delay", "hostid")
});

The exact meaning and usage of each FilterOption can be found on the Zabbix Docs under the Get section of the entity: https://www.zabbix.com/documentation/6.0/en/manual/api/reference

Attention

The 'count' option for queries is currently not supported

CRUD operations

Most entities support the CRUD operations and some include some extra Operations.
Every Crud operation can be called with either a single Entity or a List of Entities.
Every operation has a Async Variant

Integration Tests

โ— The Integration Tests are not meant to be run on a Productive System โ—
The reason for that is because they can potentially change the state of Zabbix. For example, during the HostTests, if the creation is successful but the deletion fails, Zabbix will now have a stray host that will need to be deleted manually.

The integration tests are mostly there for development purposes, so I can make changes and ensure that the base functionality of the Library is intact.

A automated set up for the test enviroment is planned.

Contribution

I welcome contributions and improvements to this library. Please feel free to open issues and submit pull requests.

Credit

Lots of Code has been reused from https://github.com/HenriqueCaires/ZabbixApi/tree/master

zabbix-6.0-api's People

Contributors

aleksey16 avatar stefan-epic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.