sensu-plugins / sensu-plugins-windows

Sensu Windows Plugins
http://sensu-plugins.io
MIT License
22 stars 46 forks source link
metrics monitoring sensu-plugins windows

Sensu-Plugins-Windows

Build Status Gem Version Appveyor status Community Slack

Functionality

These files provide basic Checks and Metrics for a Windows system.

Files

Ruby

Powershell

Usage

Example 1:

Execute Powershell functions using the helper (No copy needed), see example below:

  {
    "checks": {
      "cpu_percent": {
        "command": "c:\\opt\\sensu\\embedded\\bin\\ruby C:\\opt\\sensu\\embedded\\bin\\powershell_helper.rb check-windows-ram.ps1 90 95",
        "interval": 30,
        "type": "check",
        "handler": "win_metrics",
        "subscribers": ["win_metrics"]
      }
    }
  }
Example 2:
  {
    "checks": {
      "cpu_percent": {
        "command": "c:\\opt\\sensu\\embedded\\bin\\ruby C:\\opt\\sensu\\etc\\plugins\\metric-windows-cpu-load.rb",
        "interval": 30,
        "type": "metric",
        "handler": "win_metrics",
        "subscribers": ["win_metrics"]
      }
    }
  }

You should also include the full escaped path to the ruby interpreter in the check's command configuration, see example below:

{
  "checks": {
    "cpu_percent": {
      "command": "c:\\opt\\sensu\\embedded\\bin\\ruby C:\\opt\\sensu\\etc\\plugins\\metric-windows-cpu-load.rb",
      "interval": 30,
      "type": "metric",
      "handler": "win_metrics",
      "subscribers": ["win_metrics"]
    }
  }
}

Dependencies

Troubleshooting

Check failed to run: undefined method length' for nil:NilClass, "c:/opt/sensu/plugins/check-windows-ram.rb:45:inacquire_ram_usage'", "c:/opt/sensu/plugins/check-windows-ram.rb:54:in run'", "c:/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.

Testing

Installation and Updates

Windows Platform testing is moving to Pester as Powershell is the native language for the OS.

All tests should be written using Pester 4 syntax. For the differences please read this

In Windows 10 v1809 and higher, you first need to cleanup the default Pester module and only then you can proceed with the installation of higher version of Pester module.

$module = "C:\Program Files\WindowsPowerShell\Modules\Pester"
takeown /F $module /A /R
icacls $module /reset
icacls $module /grant Administrators:'F' /inheritance:d /T
Remove-Item -Path $Module -Recurse -Force -Confirm:$false

Install-Module -Name Pester -Force

For any subsequent update it is enough to run:

Update-Module -Name Pester

Running Tests

From the root directory run

Invoke-Pester

Installation

Installation and Setup