├── .gitattributes ├── .gitignore ├── ApplicationSet.cs ├── COPYING ├── Cmdlets ├── ConvertToZabbixDiscoveryCommand.cs ├── ExportCounterSetToZabbixTemplateCommand.cs └── GetCounterSetInstancesCommand.cs ├── DiscoveryRule.cs ├── GroupSet.cs ├── Install.ps1 ├── Item.cs ├── Properties └── AssemblyInfo.cs ├── README.md ├── System └── Diagnostics │ └── Extensions.cs ├── Template.cs ├── TemplateExport.cs ├── ZabbixTemplates.csproj ├── ZabbixTemplates.csproj.user ├── ZabbixTemplates.psd1 └── ZabbixTemplates.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | *.zip 3 | 4 | # .Net stuff 5 | *.ilk 6 | *.log 7 | *.meta 8 | *.obj 9 | *.pch 10 | *.pdb 11 | *.pgc 12 | *.pgd 13 | *.pidb 14 | *.rsp 15 | *.sbr 16 | *.scc 17 | *.sln.docstates 18 | *.suo 19 | *.svclog 20 | *.tlb 21 | *.tlh 22 | *.tli 23 | *.tmp 24 | *.tmp_proj 25 | *.user 26 | *.userosscache 27 | *.userprefs 28 | *.vspscc 29 | *.vssscc 30 | *_i.c 31 | *_i.h 32 | *_p.c 33 | .builds 34 | .vs/ 35 | [Bb]in/ 36 | [Bb]uild[Ll]og.* 37 | [Dd]ebug/ 38 | [Dd]ebugPublic/ 39 | [Ll]og/ 40 | [Oo]bj/ 41 | [Rr]elease/ 42 | [Rr]eleases/ 43 | [Tt]est[Rr]esult*/ 44 | bld/ 45 | x64/ 46 | x86/ 47 | -------------------------------------------------------------------------------- /ApplicationSet.cs: -------------------------------------------------------------------------------- 1 | namespace ZabbixTemplates 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | public class ApplicationSet : HashSet 7 | { 8 | public ApplicationSet() : base() { } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Ryan Armstrong 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | the Software, and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Cmdlets/ConvertToZabbixDiscoveryCommand.cs: -------------------------------------------------------------------------------- 1 | namespace ZabbixTemplates.Cmdlets 2 | { 3 | using System.Management.Automation; 4 | using System.Text; 5 | 6 | [Cmdlet(VerbsData.ConvertTo, "ZabbixDiscovery")] 7 | public class ConvertToZabbixDiscoveryCommand :Cmdlet 8 | { 9 | [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)] 10 | public object InputObject { get; set; } 11 | 12 | [Parameter()] 13 | public string DefaultMacroName 14 | { 15 | get { return _defaultMacroName; } 16 | set { _defaultMacroName = value; } 17 | } 18 | 19 | private StringBuilder _sb; 20 | private bool _isFirstRecord = true; 21 | 22 | private string _defaultMacroName = "INSTANCE"; 23 | 24 | protected override void BeginProcessing() 25 | { 26 | _sb = new StringBuilder(); 27 | _sb.Append(@"{""data"":["); 28 | } 29 | 30 | protected override void ProcessRecord() 31 | { 32 | // append a comma 33 | if (!_isFirstRecord) 34 | _sb.Append(","); 35 | 36 | _isFirstRecord = false; 37 | 38 | // append macros 39 | _sb.AppendFormat(@"{{""{{#{0}}}"":""{1}""}}", DefaultMacroName.ToUpperInvariant(), InputObject); 40 | } 41 | 42 | protected override void EndProcessing() 43 | { 44 | _sb.Append("]}"); 45 | WriteObject(_sb.ToString()); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Cmdlets/ExportCounterSetToZabbixTemplateCommand.cs: -------------------------------------------------------------------------------- 1 | namespace Cmdlets 2 | { 3 | using System; 4 | using System.Diagnostics; 5 | using System.Management.Automation; 6 | using ZabbixTemplates; 7 | 8 | [Cmdlet(VerbsData.Export, "CounterSetToZabbixTemplate")] 9 | public class ExportCounterSetToZabbixTemplateCommand : Cmdlet 10 | { 11 | #region Private fields 12 | 13 | private TemplateExport _export; 14 | private Template _template; 15 | 16 | private string _computerName = "."; 17 | private string _instanceName = ""; 18 | private string _templateName = ""; 19 | private string _templateGroup = "Templates"; 20 | private int _checkDelay = 60; 21 | private int _discoveryDelay = 3600; 22 | private int _discoveryLifetime = 30; 23 | private int _historyRetention = 7; 24 | private int _trendsRetention = 365; 25 | private bool _enableItems = true; 26 | private bool _activeChecks = true; 27 | 28 | #endregion 29 | 30 | #region Parameters 31 | 32 | /// 33 | /// The help 34 | /// 35 | [Parameter(Position = 0, Mandatory = true)] 36 | public string[] CounterSet { get; set; } 37 | 38 | [Parameter()] 39 | public string ComputerName 40 | { 41 | get { return _computerName; } 42 | set { _computerName = value; } 43 | } 44 | 45 | [Parameter()] 46 | public string InstanceName 47 | { 48 | get { return _instanceName; } 49 | set { _instanceName = value; } 50 | } 51 | 52 | [Parameter()] 53 | public string TemplateName 54 | { 55 | get { return _templateName; } 56 | set { _templateName = value; } 57 | } 58 | 59 | [Parameter()] 60 | public string TemplateGroup 61 | { 62 | get { return _templateGroup; } 63 | set { _templateGroup = value; } 64 | } 65 | 66 | [Parameter()] 67 | public int CheckDelay 68 | { 69 | get { return _checkDelay; } 70 | set { _checkDelay = value; } 71 | } 72 | 73 | [Parameter()] 74 | public int DiscoveryDelay 75 | { 76 | get { return _discoveryDelay; } 77 | set { _discoveryDelay = value; } 78 | } 79 | 80 | [Parameter()] 81 | public int DiscoveryLifetime 82 | { 83 | get { return _discoveryLifetime; } 84 | set { _discoveryLifetime = value; } 85 | } 86 | 87 | [Parameter()] 88 | public int HistoryRetention 89 | { 90 | get { return _historyRetention; } 91 | set { _historyRetention = value; } 92 | } 93 | 94 | [Parameter()] 95 | public int TrendsRetention 96 | { 97 | get { return _trendsRetention; } 98 | set { _trendsRetention = value; } 99 | } 100 | 101 | [Parameter()] 102 | public bool EnableItems 103 | { 104 | get { return _enableItems; } 105 | set { _enableItems = value; } 106 | } 107 | 108 | [Parameter()] 109 | public bool ActiveChecks 110 | { 111 | get { return _activeChecks; } 112 | set { _activeChecks = value; } 113 | } 114 | 115 | #endregion 116 | 117 | #region Processing 118 | 119 | protected override void BeginProcessing() 120 | { 121 | // create export document 122 | _export = new TemplateExport(); 123 | _export.Groups.Add(_templateGroup); 124 | 125 | // create default template 126 | var hostname = String.IsNullOrEmpty(_computerName) || _computerName == "." ? System.Environment.MachineName : _computerName; 127 | _template = new Template 128 | { 129 | Name = String.IsNullOrEmpty(_templateName) ? String.Format("Template Performance Counters on {0}", hostname) : _templateName, 130 | Description = "Generated with Export-CounterSetToZabbixTemplate", 131 | }; 132 | 133 | _template.Groups.Add(_templateGroup); 134 | 135 | _export.Templates.Add(_template); 136 | } 137 | 138 | protected override void ProcessRecord() 139 | { 140 | foreach (string counterSet in CounterSet) 141 | { 142 | if (!PerformanceCounterCategory.Exists(counterSet)) 143 | throw new Exception(String.Format("Performance Counter Set not found: {0}.", counterSet)); 144 | 145 | var pdhCategory = new PerformanceCounterCategory(counterSet, ComputerName); 146 | 147 | // append application 148 | var appName = String.IsNullOrEmpty(_instanceName) ? pdhCategory.CategoryName : String.Format("{0} ({1})", pdhCategory.CategoryName, _instanceName); 149 | _template.Applications.Add(appName); 150 | 151 | // append a single instance of a counter set 152 | if (pdhCategory.CategoryType == PerformanceCounterCategoryType.SingleInstance || !String.IsNullOrEmpty(_instanceName)) 153 | { 154 | foreach (var pdhCounter in pdhCategory.GetCounters()) 155 | { 156 | if (pdhCounter.IsValidForExport()) 157 | { 158 | var item = new Item(pdhCounter, InstanceName) 159 | { 160 | ItemType = ActiveChecks ? ItemType.ZabbixAgentActive : ItemType.ZabbixAgent, 161 | Status = EnableItems ? ItemStatus.Enabled : ItemStatus.Disabled, 162 | Delay = CheckDelay, 163 | History = HistoryRetention, 164 | Trends = TrendsRetention, 165 | }; 166 | 167 | item.Applications.Add(appName); 168 | 169 | _template.Items.Add(item); 170 | } 171 | } 172 | } 173 | 174 | else 175 | { 176 | var discoveryRule = new DiscoveryRule(pdhCategory) 177 | { 178 | ItemType = ActiveChecks ? ItemType.ZabbixAgentActive : ItemType.ZabbixAgent, 179 | Status = EnableItems ? ItemStatus.Enabled : ItemStatus.Disabled, 180 | Delay = DiscoveryDelay, 181 | Lifetime = DiscoveryLifetime, 182 | }; 183 | 184 | // configure item prototypes 185 | foreach (var item in discoveryRule.ItemPrototypes) 186 | { 187 | item.ItemType = ActiveChecks ? ItemType.ZabbixAgentActive : ItemType.ZabbixAgent; 188 | item.Status = EnableItems ? ItemStatus.Enabled: ItemStatus.Disabled; 189 | item.Delay = CheckDelay; 190 | item.History = HistoryRetention; 191 | item.Trends = TrendsRetention; 192 | item.Applications.Add(appName); 193 | } 194 | 195 | _template.DiscoveryRules.Add(discoveryRule); 196 | } 197 | } 198 | } 199 | 200 | protected override void EndProcessing() 201 | { 202 | WriteObject(_export.ToXmlString()); 203 | } 204 | 205 | #endregion 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /Cmdlets/GetCounterSetInstancesCommand.cs: -------------------------------------------------------------------------------- 1 | namespace ZabbixTemplates.Cmdlets 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Management.Automation; 9 | using System.Diagnostics; 10 | 11 | [Cmdlet("Get", "CounterSetInstances")] 12 | public class GetCounterSetInstancesCommand : Cmdlet 13 | { 14 | [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)] 15 | [ValidateNotNullOrEmpty] 16 | public String CounterSet { get; set; } 17 | 18 | protected override void EndProcessing() 19 | { 20 | if (!PerformanceCounterCategory.Exists(CounterSet)) 21 | throw new Exception(String.Format("Cannot find any performance counter sets on the localhost computer that match the following: {0}.", CounterSet)); 22 | 23 | var pdhCounterSet = new PerformanceCounterCategory(CounterSet); 24 | if (pdhCounterSet.CategoryType != PerformanceCounterCategoryType.MultiInstance) 25 | throw new Exception(String.Format("Performance Counter Set {0} does not have multiple instances", CounterSet)); 26 | 27 | var instances = pdhCounterSet.GetInstanceNames(); 28 | foreach (var instance in instances) 29 | { 30 | WriteObject(instance); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DiscoveryRule.cs: -------------------------------------------------------------------------------- 1 | namespace ZabbixTemplates 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | 7 | public class DiscoveryRule 8 | { 9 | public DiscoveryRule() 10 | { 11 | ItemPrototypes = new ItemCollection(); 12 | } 13 | 14 | public DiscoveryRule(PerformanceCounterCategory pdhCategory) : this() 15 | { 16 | Name = String.Format("{0} discovery", pdhCategory.CategoryName); 17 | Description = String.Format(@"{0} 18 | 19 | * Note* 20 | This discovery rule requires the 'perf_counter.discovery[]' key to be configured on the remote agent to execute the 'Get-CounterSetInstances' Cmdlet. 21 | ", pdhCategory.CategoryHelp); 22 | 23 | Key = String.Format(@"perf_counter.discovery[""{0}""]", pdhCategory.CategoryName); 24 | 25 | /* 26 | * If instances exist on the source machine, search counters on each instance. 27 | * Otherwise just call GetCounters() on an empty instance. 28 | */ 29 | var counters = new Dictionary(); 30 | var instances = pdhCategory.GetInstanceNames(); 31 | if (instances.Length > 0) 32 | { 33 | foreach (var instance in instances) 34 | { 35 | foreach (var pdhCounter in pdhCategory.GetCounters(instance)) 36 | { 37 | if(pdhCounter.IsValidForExport()) 38 | counters[pdhCounter.CounterName] = pdhCounter; 39 | } 40 | } 41 | } 42 | else 43 | { 44 | foreach (var pdhCounter in pdhCategory.GetCounters()) 45 | { 46 | if(pdhCounter.IsValidForExport()) 47 | counters[pdhCounter.CounterName] = pdhCounter; 48 | } 49 | 50 | } 51 | 52 | foreach(var pdhCounter in counters.Values) 53 | { 54 | ItemPrototypes.Add(new Item{ 55 | Name = String.Format("{0} on {{#INSTANCE}}", pdhCounter.CounterName), 56 | Key = String.Format(@"perf_counter[""\{0}({{#INSTANCE}})\{1}""]", pdhCategory.CategoryName, pdhCounter.CounterName), 57 | Description = pdhCounter.CounterHelp, 58 | }); 59 | } 60 | } 61 | 62 | private int _delay = 3600; 63 | private int _lifetime = 30; 64 | 65 | public string Name { get; set; } 66 | public string Description { get; set; } 67 | public ItemType ItemType { get; set; } 68 | public string Key { get; set; } 69 | public ItemStatus Status { get; set; } 70 | public ItemCollection ItemPrototypes {get; protected set;} 71 | 72 | public int Delay 73 | { 74 | get { return _delay; } 75 | set { _delay = value; } 76 | } 77 | 78 | public int Lifetime 79 | { 80 | get { return _lifetime; } 81 | set { _lifetime = value; } 82 | } 83 | } 84 | 85 | public class DiscoveryRuleCollection : List 86 | { 87 | public DiscoveryRuleCollection() : base() { } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /GroupSet.cs: -------------------------------------------------------------------------------- 1 | namespace ZabbixTemplates 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | public class GroupSet : HashSet 7 | { 8 | public GroupSet() : base() { } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Install.ps1: -------------------------------------------------------------------------------- 1 | # Create module directory 2 | #$modulePath = "${HOME}\Documents\WindowsPowerShell\Modules\ZabbixTemplates" 3 | $modulePath = "${PSHome}\Modules\ZabbixTemplates" 4 | New-Item -Path $modulePath -Type Directory -ErrorAction SilentlyContinue 5 | 6 | # Unload module 7 | Remove-Module -Name ZabbixTemplates # -ErrorAction SilentlyContinue 8 | 9 | # Copy module 10 | Copy-Item -Force -Path .\bin\Release\ZabbixTemplates.dll -Destination $modulePath 11 | Copy-Item -Force -Path .\ZabbixTemplates.psd1 -Destination $modulePath 12 | 13 | # Test import 14 | Import-Module -Name "ZabbixTemplates" -Verbose -------------------------------------------------------------------------------- /Item.cs: -------------------------------------------------------------------------------- 1 | namespace ZabbixTemplates 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | 7 | public class Item 8 | { 9 | public Item() 10 | { 11 | Applications = new ApplicationSet(); 12 | } 13 | 14 | public Item (PerformanceCounter pdhCounter, String instanceName = "") : this() { 15 | Name = pdhCounter.CounterName; 16 | Description = pdhCounter.CounterHelp; 17 | Key = String.IsNullOrEmpty(instanceName) ? 18 | String.Format(@"perf_counter[""\{0}\{1}""]", pdhCounter.CategoryName, pdhCounter.CounterName) : 19 | String.Format(@"perf_counter[""\{0} ({1})\{2}""]", pdhCounter.CategoryName, instanceName, pdhCounter.CounterName); 20 | } 21 | 22 | private int _delay = 60; 23 | private int _history = 7; 24 | private int _trends = 365; 25 | 26 | public string Name { get; set; } 27 | public string Description { get; set; } 28 | public ItemType ItemType { get; set; } 29 | public string Key { get; set; } 30 | public ItemStatus Status { get; set; } 31 | public ApplicationSet Applications { get; protected set; } 32 | 33 | public int Delay 34 | { 35 | get { return _delay; } 36 | set { _delay = value; } 37 | } 38 | 39 | public int History 40 | { 41 | get { return _history; } 42 | set { _history = value; } 43 | } 44 | 45 | public int Trends 46 | { 47 | get { return _trends; } 48 | set { _trends = value; } 49 | } 50 | } 51 | 52 | public class ItemCollection : List 53 | { 54 | public ItemCollection() : base() { } 55 | } 56 | 57 | public enum ItemType { 58 | ZabbixAgent = 0, 59 | ZabbixAgentActive = 7 60 | } 61 | 62 | public enum ItemStatus 63 | { 64 | Enabled = 0, 65 | Disabled = 1, 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ZabbixTemplates")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ZabbixTemplates")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("6fda77fa-7d4c-4382-8764-c56d9bf290fa")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZabbixTemplates 2 | 3 | A PowerShell module for working with Zabbix Templates 4 | 5 | ## Installation 6 | 7 | To use this module from within the Zabbix agent, is must be loaded by default 8 | for all users. This means you can't load the module using a profile script or 9 | from a particular user's Documents directory. 10 | 11 | * Create the following directory: 12 | `$PSHome\Modules\ZabbixTemplates` 13 | * Build the `Release` configuration of the module library using 14 | Visual Studio 2016 15 | * Copy the following files directly into the created Modules directory: 16 | 17 | * `bin/Release/ZabbixTemplates.dll` 18 | * `ZabbixTemplates.psd1` 19 | 20 | * Open a new PowerShell session and test that the module is loaded correctly 21 | with: 22 | 23 | > Get-Module -Name ZabbixTemplates 24 | 25 | 26 | ## Zabbix agent configuration 27 | 28 | Any Zabbix Templates generated with `Export-CounterSetToZabbixTemplate` requires 29 | the `perf_counter.discovery` user parameter key if the template includes 30 | discovery rules. 31 | 32 | This key is currently not built in to the Zabbix Windows agent. See Zabbix 33 | feature request [ZBXNEXT-2247](https://support.zabbix.com/browse/ZBXNEXT-2247) 34 | for more information. 35 | 36 | To enable the required keys, first install this module on any agent system 37 | you wish to monitor. Then add the following User Parameter to the Zabbix agent 38 | configuration file on the same systems: 39 | 40 | UserParameter=perf_counter.discovery[*],%systemroot%\system32\windowspowershell\v1.0\powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Get-CounterSetInstances -CounterSet $1 | ConvertTo-ZabbixDiscovery" 41 | 42 | 43 | Test the configuration using `zabbix_get`: 44 | 45 | $ zabbix_get -s 127.0.0.1 -k perf_counter.discovery[LogicalDisk] 46 | 47 | -------------------------------------------------------------------------------- /System/Diagnostics/Extensions.cs: -------------------------------------------------------------------------------- 1 | namespace System.Diagnostics 2 | { 3 | public static class Extensions 4 | { 5 | public static bool IsValidForExport(this PerformanceCounter pdhCounter) 6 | { 7 | return !( 8 | pdhCounter.CounterName == pdhCounter.CategoryName 9 | || pdhCounter.CounterName == "No name" 10 | || pdhCounter.CounterName == "Not displayed"); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Template.cs: -------------------------------------------------------------------------------- 1 | namespace ZabbixTemplates 2 | { 3 | using System.Collections.Generic; 4 | 5 | public class Template 6 | { 7 | public Template() 8 | { 9 | Items = new ItemCollection(); 10 | DiscoveryRules = new DiscoveryRuleCollection(); 11 | Groups = new GroupSet(); 12 | Applications = new ApplicationSet(); 13 | } 14 | 15 | public string Name { get; set; } 16 | public string Description { get; set; } 17 | public ItemCollection Items { get; protected set; } 18 | public DiscoveryRuleCollection DiscoveryRules { get; protected set; } 19 | public GroupSet Groups { get; protected set; } 20 | public ApplicationSet Applications { get; protected set; } 21 | } 22 | 23 | public class TemplateCollection : List