robotframework-listener-icinga 1.0.4
A Robot Framework listener for reporting via Icinga2 API.
License: Apache-2.0
Requires Python: >=3.8

========
Overview
========

A `Robot Framework listener <https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#listener-interface>`_  for reporting via `Icinga2 API <https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/>`_.

* Free software: Apache Software License 2.0

Installation
============

If used with rcc.exe see conda.yaml below.
Else just install the regular way like this:

::

    pip install robotframework-listener-icinga

You can also install the in-development version with::

    pip install https://gitlab.com/dominik.riva/robotframework-listener-icinga/-/archive/main/robotframework-listener-icinga-main.zip


Documentation
=============


The following example uses the `rcc.exe <https://github.com/robocorp/rcc>`_  from robocorp as a stable platform to run your robot framework scenarios.
The robot scenario below is a simple test based on the `example-windows-calculator <https://github.com/robocorp/example-windows-calculator/tree/8913ccc1e73f05412b92a27f075592d7675c5144>`_ (switched to python in newest commit).

conda.yaml (see - robotframework-listener-icinga)

.. code-block:: yaml

    channels:
    # Define conda channels here. 
    - conda-forge

    dependencies:
    # Define conda packages here. 
    # If available, always prefer the conda version of a package, installation will be faster and more efficient.
    # https://anaconda.org/search  
    - python=3.9.13                 # https://pyreadiness.org/3.9/ 
    - pip=22.2.2                    # https://pip.pypa.io/en/stable/news/
    - pip:
        # Define pip packages here. 
        # https://pypi.org/
        - rpaframework==26.1.0        # https://rpaframework.org/releasenotes.html
        - pip-system-certs==4.0       # required to access system cert store
        - robotframework-listener-icinga==1.0.0



robot.yaml (see --listener icinga)

.. code-block:: yaml

    tasks:
    Id Based Calculator Demo:
        command:
        - python
        - -m
        - robot
        - --report
        - NONE
        - --outputdir
        - output
        - --logtitle
        - Task log
        - --listener
        - icinga
        - tasks.robot
    condaConfigFile: conda.yaml
    ignoreFiles:
    - .gitignore
    artifactsDir: output
    PATH:
    - .
    PYTHONPATH:
    - .

Robots can be build with `robot framework <https://robotframework.org/>`_ keywords or straight up Python.

tasks.robot (noting about the listener in this file)

.. code-block:: yaml

    *** Settings ***
    Library           String
    Library           RPA.Windows
    Library           Collections
    Task Teardown     Close Window     name:Rechner

    *** Keywords ***
    Open the Rechner
        Windows Search    Rechner
        #Foreground Window    Rechner

    Compare result
        [Arguments]    ${first}
        ${result}=    Get Attribute    id:CalculatorResults    Name
        Should Contain    ${result}    ${first}

    Add two numbers using app ids
        [Arguments]    ${first}    ${second}    ${third}
        Click    id:clearEntryButton
        Click    id:num${first}Button
        Click    id:plusButton
        Click    id:num${second}Button
        Click    id:equalButton
        Log results
        Compare result    ${third}

    Approximate pi
        [Arguments]    ${first}    ${second}    ${third}
        Click    id:clearEntryButton
        Send Keys    Rechner    ${first}
        Click    id:divideButton
        Send Keys    Rechner    ${second}
        Click    id:equalButton
        Log results
        Compare result    ${third}

    Log results
        ${result}=    Get Attribute    id:CalculatorResults    Name
        Log    ${result}
        Screenshot    Rechner   %{ROBOT_ARTIFACTS}${/}${TEST_NAME}id-based-result.png

    *** Tasks ***
    Addition
        Open the Rechner
        Add two numbers using app ids    9    5    14
    Division
        Open the Rechner
        Approximate pi    355    113    3.14159292035

devdata\\env.json (see ICINGA_* variables)

.. code-block:: yaml

    {
        "RPA_SECRET_MANAGER": "RPA.Robocorp.Vault.FileSecrets",
        "RPA_SECRET_FILE": "C:\\Users\\USER\\vault.json",
        "ICINGA_FQDN": "icinga.example.com",
        "ICINGA_HOST_NAME": "testrobot.example.com",
        "ICINGA_SERVICE_NAME": "Passive - Robot Framework - example-windows-calculator - Id-Based",
        "ICINGA_TTL": "900"
    }

C:\\Users\\USER\\vault.json (must match preconfigured Icinga2 API user - pull request for certificate based auth are welcomed)

.. code-block:: yaml

    {
        "icinga": {
            "api_user": "robotframework",
            "api_pass": "ADD_STRONG_PASSWORD"
        }
    }

Icinga DSL generated by director preview of the host object.
The Service "Passive - Robot Framework - example-windows-calculator - Id-Based" the above robot scenario listener is targeting.
The variable "robot_framework_thresholds" allows to set thresholds and overwrite robot framework status.

.. code-block::

    zones.d/master/hosts.conf
    object Host "vd418164.example.com" {
        import "tpl-host-windows"
        import "116-tpl-host-agent"

        display_name = "VD418164"
        address = "10.6.160.71"
        notes = "Robot Framework Entwicklungsroboter"
        groups = [ "Monitoring", "Robot Framework Robots" ]
        vars["_override_servicevars"] = {
            "Icingacli vSphereDB - VM Status" = {
                "116_check_icingacli_vspheredb_name" = "VD418164"
            }
            "Passive - Robot Framework - example-windows-calculator - Id-Based" = {
                robot_framework_thresholds = "{\"Tasks.Addition\": {\"warning\": \"0:14000\", \"critical\": \"0:16000\", \"status\": \"PASS\"}, \"Tasks.Division\": {\"warning\": \"0:15000\", \"critical\": \"0:18000\", \"status\": \"PASS\"}, \"Tasks\": {\"warning\": \"0:24000\", \"critical\": \"0:25000\", \"status\": \"PASS\"}}"
            }
            "Service - MSDTC" = {
                service_windows_starttype = "manual"
            }
            "Service - W32Time" = {
                service_windows_starttype = "manual"
            }
        }
        vars.custom_tags = [
            "robot-framework_sap",
            "robot-framework_isop",
            "vspheredb-vm",
            "robot-framework_kda",
            "robot-framework_meona-pflege",
            "robot-framework_meona-arzt",
            "robot-framework_patientenportal",
            "robot-framework_cardioapp",
            "robot-framework_patientenarchivviewer",
            "robot-framework_example-windows-calculator"
        ]
        vars.robot_framework_thresholds = "{\"Addition\": {\"warning\": \"0:12\", \"critical\": \"0:15\"}, \"Division\": {\"warning\": \"0:15\", \"critical\": \"0:18\"}, \"Tasks\": {\"warning\": \"0:20\", \"critical\": \"0:25\"}}"
        vars.tags = [ "windows" ]
        vars.teams = [ "Entwicklung_Monitoring" ]
    }

    zones.d/master/agent_endpoints.conf
    object Endpoint "vd418164.example.com" {
        host = "10.6.160.71"
        log_duration = 0s
    }

    zones.d/master/agent_zones.conf
    object Zone "vd418164.example.com" {
        parent = "master"
        endpoints = [ "vd418164.ms.uhbs.ch" ]
    }


Screenshots
===========

With ignore keywords set to True:

.. image:: screenshot_with_ignore_keywords_ok.png
.. image:: screenshot_with_ignore_keywords_warn.png
.. image:: screenshot_with_ignore_keywords.png
.. image:: screenshot_with_ignore_keywords_performancedata.png

With ignore keywords set ot False:

.. image:: screenshot_with_keywords.png
.. image:: screenshot_with_keywords_performancedata.png


Development
===========

Pull request for Tox and pytest very welcomed!

To run all the tests run::

    tox

Note, to combine the coverage data from all the tox environments run:

.. list-table::
    :widths: 10 90
    :stub-columns: 1

    - - Windows
      - ::

            set PYTEST_ADDOPTS=--cov-append
            tox

    - - Other
      - ::

            PYTEST_ADDOPTS=--cov-append tox


Changelog
=========

0.0.0 (2023-07-07)
------------------

* First release on PyPI.