Development Modules

icingaweb2

(Gleber Ribeiro Leite) #1

I’m trying to develop a module for SNMP scanning on a host.
I have done some tests and currently for my “scripts” to work, “be read”, I have to put them in the /usr/share/icingaweb2/public/ folder.
how do I get my php scripts to be found inside the /usr/share/icingaweb2/modules/new_module folder, for example?


(Michael Friedrich) #2

Hi,

how I would do it - I am always looking into existing code on whether this problem for retrieving a module path or anything else has been done already.

First off, decide whether such a script should be called from the web application via system() call, or implement its functionality into the module itself within PHP. That way you can create both - a call from within the web forms, and additionally CLI commands. The x509 module for instance implements a scan functionality for the entire network, directly as CLI command. Calling a shell script from PHP works, but it doesn’t feel right and it opens room for parameter exploitation.

In order to access specific module class functions, you’ll need to fetch them from registered modules first with

$this->app->getModuleManager()

and call

getModuleDir("modulename")

on it to retrieve the current module path. You can check the generic module list command or multiple use cases for reference.

Cheers,
Michael