Icinga2 and Power Shell external scripts with NSClient++ NSCA

This forum was archived to /woltlab and is now in read-only mode.
  • Dear All,
    I'm new on this portal and I noticed that there are a lot of experienced people who want and can help.
    I want to send information from NSClient++ NSCA to Icinga2 about specific file size.
    If file size is bigger then certain size I need RED warning - alert in Icinga2 dashboard.
    I'm using Power Shell external script which looks like:


    $colItems = (Get-ChildItem C:\Intel ubuntu-16.04-server-amd64.iso -recurse | Measure-Object -property length -sum)
    $filesize = "{0:N2}" -f ($colItems.sum / 1GB) + " GB"
    if($filesize -gt '0.5')
    {$result = 'Warning'}
    else
    {$result = 'Ok'}



    $result


    In NSClient++ I defined command which read external script from file and command is:
    alias_check_file_size_warning = cmd /c echo scripts\file_size_warning.ps1; exit($lastexitcode) | powershell.exe -command -


    My Icinga 2 is get information from this script but in dashboard it is only writhed "warning" with GREEN field (picture is in attachment).


    How can I fix this in order that my Icinga2 display this in dashboard like RED filed because it is a warning ?

  • You should do two things:

    • Read the nagios plugin guidelines
    • Check the Return Value of your command, i bet it is 0 for OK instead of 1 for warning.


    With powershell, users often run in a trap with the return value. Read that:
    http://joshua.poehls.me/2012/p…cript-module-boilerplate/


    Short, that works:

    Code: batch.cmd
    1. @echo off
    2. powershell -file test.ps1
    3. REM Just a debug output, comment out for "production" use
    4. echo %ERRORLEVEL%


    Code: test.ps1
    1. "DISK WARNING - free space: / 3326 MB (56%);"
    2. exit 1

    The post was edited 2 times, last by sru ().