In my second and last blog I want to talk about the procedure for writing Icinga Web 2 modules (icingaweb2-modules) for NetEye. This will be my last blog because as of today, I will sadly leave this company. In my short time here I’ve had the occasion to learn the art of making own Icinga Web 2 modules. All told, I had the pleasure of developing two different modules. One was the customactions-module, which I’ve already written an article about. Since then I spent more time on the ondutymanager-module, which customizes notifications and their contacts. But in this article, I don’t want to go into detail on the ondutymanager, but rather provide more insights about what it really means to develop Icinga Web 2 modules and which classes NetEye offers to accelerate the process and avoid duplication.
Where do I get documentation?
Documentation is really difficult to find for developing Icinga Web 2 modules. The web in general doesn’t offer much information and neither does NetEye. My way of becoming more familiar with the different classes and helpers was to reverse engineer things. In other words, looking into the different base classes NetEye implements and analyzing the functions they offer, which can be used for different purposes, trying to understand how these are all connected under the hood, and how they can be reused. I also found it useful to go into a module in the web interface, click on an interesting controller, look at its functionality, and then go into the code and try to understand which parts of the code create the element of the web interface.
I spent my first days analyzing just the Tornado module, which in reality is not the best module to learn the structure and getting a general overview, because it’s a lot different from all the other modules. After that I spent a lot of time looking into the base classes and checking what the purpose of each one is. Understanding them is very crucial for effectively creating modules.
What are the BaseClasses?
Often some parts of a use case of a module are the same: creating a database which stores different entities in different tables, retrieving them, and then maybe updating or deleting them. In a nutshell, making basic “CRUD” operations.
NetEye provides different classes that can be implemented to avoid writing lots of code rows for achieving this result. Some of these BaseClasses are:
The enormous advantage of these classes is that every desired component needs only 8 files and maybe a combined 100 lines of code (which are only the class declarations and do not contain any custom code) and it is already fully implemented, so it displays the models in a table with the elements editable in a web form. In addition, it allows you to create new objects and to delete existing ones.
My personal advice
The beginning can be frustrating. Really frustrating even, depending on your knowledge. The biggest problem when you start to develop Icinga Web 2 modules is the missing (or better said, the small amount of) documentation. Start by looking at the BaseClasses and try to understand more or less their purpose. In the beginning, you don’t have to understand every single bit in the smallest detail, but to get yourself a general overview.
Also look at other modules, especially how they are implemented and how they are structured. Often, they already have the exact same functionalities you need in your module. Therefore, here’s another tip: If you don’t know how to solve a problem, click through all the modules in the web interface and look to see if they contain the element(s) you need. If it does, go into the code of the module, search for the right chunk, and copy it into your module. Afterwards change it so that it works like it should in your module. It’s important that you understand what you are copying by diving deeply into the code, because maybe in the future you’ll need exactly this functionality and now you’ll know where to find it.
The first module will be the most challenging one. There will be many uncertainties, but with every new class and function you write, you’ll become more and more familiar with the process. As soon as you know where to find the desired functions and how to create your own components, you’ll become really fast and it will become fun and motivating to write your code and then see the results.
I hope this article gives you some small insight into the world of Icinga Web 2 modules, and that now you feel ready to begin developing your first own module!