Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Add more functions #73

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ConsoleAppZabbixTest/ConsoleAppZabbixTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ZabbixApiTests\ZabbixApiTests.csproj" />
<ProjectReference Include="..\ZabbixApi\ZabbixApi.csproj" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions ConsoleAppZabbixTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using ZabbixApi;
namespace ConsoleAppZabbixTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var a = new ZabbixApi.Context();

}
}
}
19 changes: 19 additions & 0 deletions ZabbixApi/Entities/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public partial class Host : EntityBase
[JsonProperty("hostid")]
public override string Id { get; set; }

/// <summary>
/// Host Description
/// </summary>
public string description { get; set; }

/// <summary>
/// Technical name of the host.
/// </summary>
Expand Down Expand Up @@ -255,6 +260,10 @@ public partial class Host : EntityBase
/// </summary>
public IList<HostGroup> groups { get; set; }

/// <summary>
/// Host Tags
/// </summary>
public IList<Tag> tags { get; set; }
/// <summary>
/// Templates
/// </summary>
Expand Down Expand Up @@ -472,4 +481,14 @@ public Host()

#endregion
}


/// <summary>
/// Class to support tags while updating or inserting a HOST
/// </summary>
/* public class Tag
{
public string tag { get; set; }
public string value { get; set; }
}*/
}
10 changes: 10 additions & 0 deletions ZabbixApi/Entities/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ public Map()

#endregion
}
public partial class MapElementSE : EntityBase
{
[JsonProperty("hostid")]
public override string Id { get; set; }
public string groupid { get; set; }
}

public partial class MapElement : EntityBase
{
Expand All @@ -415,6 +421,8 @@ public partial class MapElement : EntityBase
/// </summary>
public string elementid { get; set; }

public IList<MapElementSE> elements { get; set; }

/// <summary>
/// Type of map element. 
///
Expand Down Expand Up @@ -533,6 +541,8 @@ public partial class MapElement : EntityBase
/// </summary>
public int x { get; set; }



/// <summary>
/// Y-coordinates of the element in pixels. 
///
Expand Down
91 changes: 91 additions & 0 deletions ZabbixApi/Entities/Problem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using ZabbixApi.Helper;

namespace ZabbixApi.Entities
{
public partial class Problem : EntityBase
{
#region Properties
/// <summary>
/// ID of the problem event.
/// </summary>
[JsonProperty("eventid")]
public string Id { get; set; }
/// <summary>
/// Type of the problem event.
/// Possible values:
/// 0 - event created by a trigger
/// 3 - internal event.
/// Default: 0 - problem created by a trigger.
/// </summary>
public string source { get; set; }
/// <summary>
/// Type of object that is related to the problem event.
/// Possible values for trigger events:
/// 0 - trigger.
/// Possible values for internal events:
/// 0 - trigger;
/// 4 - item;
/// 5 - LLD rule.
/// </summary>
[JsonProperty("object")]
public string _object { get; set; }
/// <summary>
/// ID of the related object.
/// </summary>
[JsonProperty("objectid")]
public string _objectid { get; set; }
/// <summary>
/// Time when the problem event was created.
/// </summary>
[JsonConverter(typeof(TimestampToDateTimeConverter))]
public DateTime clock { get; set; }
/// <summary>
/// Nanoseconds when the problem event was created.
/// </summary>
public string ns { get; set; }
/// <summary>
/// Recovery event ID.
/// </summary>
public string r_eventid { get; set; }
/// <summary>
/// Time when the recovery event was created.
/// </summary>
public string r_clock { get; set; }
/// <summary>
/// Nanoseconds when the recovery event was created.
/// </summary>
public string r_ns { get; set; }
/// <summary>
/// Correlation rule ID if this event was recovered by global correlation rule.
/// </summary>
public string correlationid { get; set; }
/// <summary>
/// User ID if the problem was manually closed.
/// </summary>
public string userid { get; set; }
/// <summary>
/// true - return acknowledged problems only;
/// false - unacknowledged only.
/// </summary>
public string acknowledged { get; set; }
/// <summary>
/// Return only problems with given trigger severities. Applies only if object is trigger.
/// </summary>
public int severity { get; set; }
/// <summary>
/// true - return only suppressed problems;
/// false - return problems in the normal state.
/// </summary>
public string supressed { get; set; }
#endregion

#region Associations
public IList<Acknowledge> acknowledges { get; set; }

#endregion
}
}
43 changes: 43 additions & 0 deletions ZabbixApi/Entities/Trend.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZabbixApi.Helper;

namespace ZabbixApi.Entities
{
public partial class Trend : EntityBase
{
#region Properties
/// <summary>
/// Time when that value was received.
/// </summary>
[JsonConverter(typeof(TimestampToDateTimeConverter))]
public DateTime clock { get; set; }
/// <summary>
/// ID of the related item.
/// </summary>
[JsonProperty("itemid")]
public override string Id { get; set; }
/// <summary>
/// Number of values within this hour.
/// </summary>
public int num { get; set; }
/// <summary>
/// Hourly minimum value.
/// </summary>
public string value_min { get; set; }
/// <summary>
/// Hourly average value.
/// </summary>
public string value_avg { get; set; }
/// <summary>
/// Hourly maximum value.
/// </summary>
public string value_max { get; set; }

#endregion
}
}
7 changes: 7 additions & 0 deletions ZabbixApi/IContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using ZabbixApi.Entities;
using ZabbixApi.Helper;
using ZabbixApi.Services;

Expand Down Expand Up @@ -59,6 +60,8 @@ public interface IContext : IDisposable
IUserGroupService UserGroups { get; }
IGlobalMacroService GlobalMacros { get; }
IHostMacroService HostMacros { get; }
ITrendService Trend { get; }
IProblemService Problem { get; }
IUserService Users { get; }
IValueMapService ValueMaps { get; }
}
Expand Down Expand Up @@ -160,6 +163,8 @@ private void Initialize(string url)
GlobalMacros = new GlobalMacroService(this);
HostMacros = new HostMacroService(this);
Users = new UserService(this);
Trend = new TrendService(this);
Problem = new ProblemService(this);
ValueMaps = new ValueMapService(this);
}

Expand Down Expand Up @@ -269,6 +274,7 @@ private Request GetRequest(object @params, string method, string authenticationT
};
}

public ITrendService Trend { get; private set; }
public IActionService Actions { get; private set; }
public IAlertService Alerts { get; private set; }
public ApiInfoService ApiInfo { get; private set; }
Expand Down Expand Up @@ -309,6 +315,7 @@ private Request GetRequest(object @params, string method, string authenticationT
public IGlobalMacroService GlobalMacros { get; private set; }
public IHostMacroService HostMacros { get; private set; }
public IUserService Users { get; private set; }
public IProblemService Problem { get; private set; }
public IValueMapService ValueMaps { get; private set; }

private class Request
Expand Down
39 changes: 39 additions & 0 deletions ZabbixApi/Services/ProblemService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using ZabbixApi.Entities;
using ZabbixApi.Helper;

namespace ZabbixApi.Services
{
public interface IProblemService
{
IEnumerable<Problem> Get(object filter = null, IEnumerable<ProblemInclude> include = null, Dictionary<string, object> @params = null);

}
public class ProblemService : ServiceBase<Problem, ProblemInclude>, IProblemService
{
public ProblemService(IContext context) : base(context, "problem") { }
protected override Dictionary<string, object> BuildParams(object filter = null, IEnumerable<ProblemInclude> include = null, Dictionary<string, object> @params = null)
{
var includeHelper = new IncludeHelper(include == null ? 1 : include.Sum(x => (int)x));

@params = @params ?? new Dictionary<string, object>();
@params.AddIfNotExist("output", "extend");
@params.AddIfNotExist("selectAcknowledges","extend");
@params.AddOrReplace("filter", filter);

return @params;
}



}
public enum ProblemInclude
{
All = 1,
None = 2
}
}
34 changes: 34 additions & 0 deletions ZabbixApi/Services/TrendService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ZabbixApi.Entities;
using ZabbixApi.Helper;

namespace ZabbixApi.Services
{
public interface ITrendService
{
IEnumerable<Trend> Get(object filter = null, IEnumerable<TrendInclude> include = null, Dictionary<string, object> @params = null);

}
public class TrendService : ServiceBase<Trend, TrendInclude>, ITrendService
{
public TrendService(IContext context) : base(context, "trend") { }
protected override Dictionary<string, object> BuildParams(object filter = null, IEnumerable<TrendInclude> include = null, Dictionary<string, object> @params = null)
{
var includeHelper = new IncludeHelper(include == null ? 1 : include.Sum(x => (int)x));

@params = @params ?? new Dictionary<string, object>();
@params.AddIfNotExist("output", "extend");
@params.AddOrReplace("filter", filter);

return @params;
}
}
public enum TrendInclude
{
All = 1,
None = 2
}
}
8 changes: 4 additions & 4 deletions ZabbixApi/ZabbixApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Zabbix</PackageId>
<PackageId>ZabbixCG</PackageId>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Authors>Henrique Caires</Authors>
<Authors>Henrique Caires/André Guergolet/Luan Santos</Authors>
<PackageTags>Zabbix ZabbixApi</PackageTags>
<PackageProjectUrl>https://github.com/HenriqueCaires/ZabbixApi</PackageProjectUrl>
<PackageIconUrl>https://www.zabbix.com/favicon.ico</PackageIconUrl>
<RepositoryUrl>https://github.com/HenriqueCaires/ZabbixApi</RepositoryUrl>
<RepositoryType>GIT</RepositoryType>
<VersionPrefix>4.0.7</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionPrefix>4.0.7</VersionPrefix>
<VersionSuffix></VersionSuffix>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
18 changes: 18 additions & 0 deletions ZabbixApiTests/Integration/ProblemServiceIntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;

namespace ZabbixApiTests.Integration
{
public class ProblemServiceIntegrationTest : IntegrationTestBase
{
[Fact]
public void MustGetAny()
{
var result = context.Problem.Get().Where(x => x._objectid == "55578").ToList();
Assert.NotNull(result);
}
}
}
Loading