Skip to content
Daniel edited this page Feb 18, 2021 · 1 revision

Join Development

Do you want to modify the source code of the openITCOCKPIT Monitoring Agent? If yes follow this guide to getting started.

Please make sure you have Golang >= 1.15.6 and Visual Studio Code installed.

  1. Clone this repository
git clone https://github.com/it-novum/openitcockpit-agent-go.git
  1. Run Visual Studio Code and make sure that you have installed the Go extension Install Go extension for VS Code

  2. Install Go tools Press ctrl + shift + P (Windows and Linux) or cmd + shift + P on macOS and select Go: Install/Update Tools Install Go tools

Select all tools and confirm with Ok Select and install Go tools

The installation is completed, as soon as you see All tools successfully installed. You are ready to Go :). in the VS Code terminal

  1. Setup VS Code Press ctrl + shift + P (Windows and Linux) or cmd + shift + P on macOS and type settings json and select Preferences: Open Settings (JSON). Add the following settings to your JSON.
    "go.testTimeout": "90s",
    "go.useLanguageServer": true,
    
    // Remove this if you do NOT want to enable libvirt
    "go.toolsEnvVars": {
        "GOFLAGS": "-tags=libvirt"
    },
    "go.lintTool": "golangci-lint",
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
        // Optional: Disable snippets, as they conflict with completion ranking.
        "editor.snippetSuggestions": "none",
    },
    "[go.mod]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
    },
    "gopls": {
        // Add parameter placeholders when completing a function.
        "usePlaceholders": true,

        // If true, enable additional analyses with staticcheck.
        // Warning: This will significantly increase memory usage.
        "staticcheck": false,
    }

Source: https://github.com/golang/tools/blob/master/gopls/doc/vscode.md

  1. Debug Launch Configuration

In the VS Code main menu click on Run -> Open Configurations

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}",
            "env": {
                "OITC_AGENT_DEBUG": "1",
            },
            "args": ["-c", ".\\config.cnf", "--disable-logfile", "--debug"]
        }
    ]
}

Create a new file in workspace folder -> config.ini

[default]
customchecks = ./customchecks.ini

Create a new file in workspace folder -> customchecks.ini (Windows)

[check_Windows_Services_Status_OSS]
command = echo 'hello world'
interval = 15
timeout = 10
enabled = false

Create a new file in workspace folder -> customchecks.ini (Linux/macOS)

[check_echo]
command = echo 'hello world'
interval = 15
timeout = 10
enabled = false

Windows development notes

By default the agent will assume to be run as Windows Service. If you set OITC_AGENT_DEBUG it will run the default cmd like on linux.

$env:OITC_AGENT_DEBUG="1"
.\agent.exe -c C:\git\openitcockpit-agent-go\config.ini -l "$env:TEMP\agent.log"