]> granicus.if.org Git - icinga2/blob - doc/21-development.md
Docs: Update Boost setup instructions for Windows dev environment
[icinga2] / doc / 21-development.md
1 # Development <a id="development"></a>
2
3 This chapter provides hints on Icinga 2 debugging,
4 development, package builds and tests.
5
6 * [Debug Icinga 2](21-development.md#development-debug)
7     * [GDB Backtrace](21-development.md#development-debug-gdb-backtrace)
8     * [Core Dump](21-development.md#development-debug-core-dump)
9 * [Test Icinga 2](21-development.md#development-tests)
10     * [Snapshot Packages (Nightly Builds)](21-development.md#development-tests-snapshot-packages)
11 * [Develop Icinga 2](21-development.md#development-develop)
12     * [Preparations](21-development.md#development-develop-prepare)
13     * [Design Patterns](21-development.md#development-develop-design-patterns)
14     * [Build Tools](21-development.md#development-develop-builds-tools)
15     * [Unit Tests](21-development.md#development-develop-tests)
16     * [Style Guide](21-development.md#development-develop-styleguide)
17 * [Development Environment](21-development.md#development-environment)
18     * [Linux Dev Environment](21-development.md#development-linux-dev-env)
19     * [macOS Dev Environment](21-development.md#development-macos-dev-env)
20     * [Windows Dev Environment](21-development.md#development-windows-dev-env)
21 * [Package Builds](21-development.md#development-package-builds)
22     * [RPM](21-development.md#development-package-builds-rpms)
23     * [DEB](21-development.md#development-package-builds-deb)
24     * [Windows](21-development.md#development-package-builds-windows)
25 * [Advanced Tips](21-development.md#development-advanced)
26
27 <!-- mkdocs requires 4 spaces indent for nested lists: https://github.com/Python-Markdown/markdown/issues/3 -->
28
29 ## Debug Icinga 2 <a id="development-debug"></a>
30
31 This chapter targets all users who have been asked by developers to provide
32 a stack trace or coredump if the application crashed. It is also useful
33 for developers working with different debuggers.
34
35 > **Note:**
36 >
37 > This is intentionally mentioned before any development insights
38 > as debugging is a more frequent and commonly asked question.
39
40 ### Debug Requirements <a id="debug-requirements"></a>
41
42 Make sure that the debug symbols are available for Icinga 2.
43 The Icinga 2 packages provide a debug package which must be
44 installed separately for all involved binaries, like `icinga2-bin`
45 or `icinga2-ido-mysql`.
46
47 Distribution       | Command
48 -------------------|------------------------------------------
49 Debian/Ubuntu      | `apt-get install icinga2-dbg`
50 RHEL/CentOS        | `yum install icinga2-debuginfo`
51 Fedora             | `dnf install icinga2-debuginfo icinga2-bin-debuginfo icinga2-ido-mysql-debuginfo`
52 SLES/openSUSE      | `zypper install icinga2-bin-debuginfo icinga2-ido-mysql-debuginfo`
53
54 Furthermore, you may also have to install debug symbols for Boost and your C++ library.
55
56 If you're building your own binaries, you should use the `-DCMAKE_BUILD_TYPE=Debug` cmake
57 build flag for debug builds.
58
59
60 ### GDB as Debugger <a id="development-debug-gdb"></a>
61
62 Install GDB in your development environment.
63
64 Distribution       | Command
65 -------------------|------------------------------------------
66 Debian/Ubuntu      | `apt-get install gdb`
67 RHEL/CentOS        | `yum install gdb`
68 Fedora             | `dnf install gdb`
69 SLES/openSUSE      | `zypper install gdb`
70
71 #### GDB Run <a id="development-debug-gdb-run"></a>
72
73 Call GDB with the binary (`/usr/sbin/icinga2` is a wrapper script calling
74 `/usr/lib64/icinga2/sbin/icinga2` since 2.4) and all arguments and run it in foreground.
75
76 ```
77 gdb --args /usr/lib64/icinga2/sbin/icinga2 daemon -x debug
78 ```
79
80 The exact path to the Icinga 2 binary differs on each distribution. On Ubuntu
81 it is installed into `/usr/lib/x86_64-linux-gnu/icinga2/sbin/icinga2` on 64-bit systems
82 for example.
83
84 > **Note**
85 >
86 > If gdb tells you it's missing debug symbols, quit gdb and install
87 > them: `Missing separate debuginfos, use: debuginfo-install ...`
88
89 Run/restart the application.
90
91 ```
92 (gdb) r
93 ```
94
95 Kill the running application.
96
97 ```
98 (gdb) k
99 ```
100
101 Continue after breakpoint.
102
103 ```
104 (gdb) c
105 ```
106
107 #### GDB Core Dump <a id="development-debug-gdb-coredump"></a>
108
109 Either attach to the running process using `gdb -p PID` or start
110 a new gdb run.
111
112 ```
113 (gdb) r
114 (gdb) generate-core-file
115 ```
116
117 #### GDB Backtrace <a id="development-debug-gdb-backtrace"></a>
118
119 If Icinga 2 aborted its operation abnormally, generate a backtrace.
120
121 > **Note**
122 >
123 > Please install the [required debug symbols](21-development.md#debug-requirements)
124 > prior to generating a backtrace.
125
126 `thread apply all` is important here since this includes all running threads.
127 We need this information when e.g. debugging dead locks and hanging features.
128
129 ```
130 (gdb) bt
131 (gdb) thread apply all bt full
132 ```
133
134 If gdb stops at a SIGPIPE signal please disable the signal before
135 running Icinga 2. This isn't an error, but we need to workaround it.
136
137 ```
138 (gdb) handle SIGPIPE nostop noprint pass
139 (gdb) r
140 ```
141
142 If you create a [new issue](https://github.com/Icinga/icinga2/issues),
143 make sure to attach as much detail as possible.
144
145 #### GDB Backtrace from Running Process <a id="development-debug-gdb-backtrace-running"></a>
146
147 If Icinga 2 is still running, generate a full backtrace from the running
148 process and store it into a new file (e.g. for debugging dead locks).
149
150 > **Note**
151 >
152 > Please install the [required debug symbols](21-development.md#debug-requirements)
153 > prior to generating a backtrace.
154
155 Icinga 2 runs with 2 processes: main and command executor, therefore generate two backtrace logs
156 and add them to the GitHub issue.
157
158 ```
159 for pid in $(pidof icinga2); do gdb -p $pid -batch -ex "thread apply all bt full" -ex "detach" -ex "q" > gdb_bt_${pid}_`date +%s`.log; done
160 ```
161
162 #### GDB Thread List from Running Process <a id="development-debug-gdb-thread-list-running"></a>
163
164 Instead of a full backtrace, you sometimes just need a list of running threads.
165
166 ```
167 for pid in $(pidof icinga2); do gdb -p $pid -batch -ex "info threads" -ex "detach" -ex "q" > gdb_threads_${pid}_`date +%s`.log; done
168 ```
169
170 #### GDB Backtrace Stepping <a id="development-debug-gdb-backtrace-stepping"></a>
171
172 Identifying the problem may require stepping into the backtrace, analysing
173 the current scope, attributes, and possible unmet requirements. `p` prints
174 the value of the selected variable or function call result.
175
176 ```
177 (gdb) up
178 (gdb) down
179 (gdb) p checkable
180 (gdb) p checkable.px->m_Name
181 ```
182
183 #### GDB Breakpoints <a id="development-debug-gdb-breakpoint"></a>
184
185 To set a breakpoint to a specific function call, or file specific line.
186
187 ```
188 (gdb) b checkable.cpp:125
189 (gdb) b icinga::Checkable::SetEnablePerfdata
190 ```
191
192 GDB will ask about loading the required symbols later, select `yes` instead
193 of `no`.
194
195 Then run Icinga 2 until it reaches the first breakpoint. Continue with `c`
196 afterwards.
197
198 ```
199 (gdb) run
200 (gdb) c
201 ```
202
203 In case you want to step into the next line of code, use `n`. If there is a
204 function call where you want to step into, use `s`.
205
206 ```
207 (gdb) n
208
209 (gdb) s
210 ```
211
212 If you want to delete all breakpoints, use `d` and select `yes`.
213
214 ```
215 (gdb) d
216 ```
217
218 > **Tip**
219 >
220 > When debugging exceptions, set your breakpoint like this: `b __cxa_throw`.
221
222 Breakpoint Example:
223
224 ```
225 (gdb) b __cxa_throw
226 (gdb) r
227 (gdb) up
228 ....
229 (gdb) up
230 #11 0x00007ffff7cbf9ff in icinga::Utility::GlobRecursive(icinga::String const&, icinga::String const&, boost::function<void (icinga::String const&)> const&, int) (path=..., pattern=..., callback=..., type=1)
231     at /home/michi/coding/icinga/icinga2/lib/base/utility.cpp:609
232 609                     callback(cpath);
233 (gdb) l
234 604
235 605     #endif /* _WIN32 */
236 606
237 607             std::sort(files.begin(), files.end());
238 608             BOOST_FOREACH(const String& cpath, files) {
239 609                     callback(cpath);
240 610             }
241 611
242 612             std::sort(dirs.begin(), dirs.end());
243 613             BOOST_FOREACH(const String& cpath, dirs) {
244 (gdb) p files
245 $3 = std::vector of length 11, capacity 16 = {{static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/agent.conf"}, {static NPos = 18446744073709551615,
246     m_Data = "/etc/icinga2/conf.d/commands.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/downtimes.conf"}, {static NPos = 18446744073709551615,
247     m_Data = "/etc/icinga2/conf.d/groups.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/notifications.conf"}, {static NPos = 18446744073709551615,
248     m_Data = "/etc/icinga2/conf.d/satellite.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/services.conf"}, {static NPos = 18446744073709551615,
249     m_Data = "/etc/icinga2/conf.d/templates.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/test.conf"}, {static NPos = 18446744073709551615,
250     m_Data = "/etc/icinga2/conf.d/timeperiods.conf"}, {static NPos = 18446744073709551615, m_Data = "/etc/icinga2/conf.d/users.conf"}}
251 ```
252
253
254 ### Core Dump <a id="development-debug-core-dump"></a>
255
256 When the Icinga 2 daemon crashes with a `SIGSEGV` signal
257 a core dump file should be written. This will help
258 developers to analyze and fix the problem.
259
260 #### Core Dump File Size Limit <a id="development-debug-core-dump-limit"></a>
261
262 This requires setting the core dump file size to `unlimited`.
263
264
265 ##### Systemd
266
267 ```
268 systemctl edit icinga2.service
269
270 [Service]
271 ...
272 LimitCORE=infinity
273
274 systemctl daemon-reload
275
276 systemctl restart icinga2
277 ```
278
279 ##### Init Script
280
281 ```
282 vim /etc/init.d/icinga2
283 ...
284 ulimit -c unlimited
285
286 service icinga2 restart
287 ```
288
289 ##### Verify
290
291 Verify that the Icinga 2 process core file size limit is set to `unlimited`.
292
293 ```
294 for pid in $(pidof icinga2); do cat /proc/$pid/limits; done
295
296 ...
297 Max core file size        unlimited            unlimited            bytes
298 ```
299
300
301 #### Core Dump Kernel Format <a id="development-debug-core-dump-format"></a>
302
303 The Icinga 2 daemon runs with the SUID bit set. Therefore you need
304 to explicitly enable core dumps for SUID on Linux.
305
306 ```
307 sysctl -w fs.suid_dumpable=2
308 ```
309
310 Adjust the coredump kernel format and file location on Linux:
311
312 ```
313 sysctl -w kernel.core_pattern=/var/lib/cores/core.%e.%p
314
315 install -m 1777 -d /var/lib/cores
316 ```
317
318 MacOS:
319
320 ```
321 sysctl -w kern.corefile=/cores/core.%P
322
323 chmod 777 /cores
324 ```
325
326 #### Core Dump Analysis <a id="development-debug-core-dump-analysis"></a>
327
328 Once Icinga 2 crashes again a new coredump file will be written. Please
329 attach this file to your bug report in addition to the general details.
330
331 Simple test case for a `SIGSEGV` simulation with `sleep`:
332
333 ```
334 ulimit -c unlimited
335 sleep 1800&
336 [1] <PID>
337 kill -SEGV <PID>
338 gdb `which sleep` /var/lib/cores/core.sleep.<PID>
339 (gdb) bt
340 rm /var/lib/cores/core.sleep.*
341 ```
342
343 Analyzing Icinga 2:
344
345 ```
346 gdb /usr/lib64/icinga2/sbin/icinga2 core.icinga2.<PID>
347 (gdb) bt
348 ```
349
350 ### LLDB as Debugger <a id="development-debug-lldb"></a>
351
352 LLDB is available on macOS with the Xcode command line tools.
353
354 ```
355 $ xcode-select --install
356 ```
357
358 In order to run Icinga 2 with LLDB you need to pass the binary as argument.
359
360 ```
361 lldb -- /usr/local/icinga2/lib/icinga2/sbin/icinga2 daemon
362 ```
363
364 Breakpoint:
365
366 ```
367 > b checkable.cpp:57
368 > b icinga::Checkable::ProcessCheckResult
369 ```
370
371 Full backtrace:
372
373 ```
374 > bt all
375 ```
376
377 Select thread:
378
379 ```
380 > thr sel 5
381 ```
382
383 Step into:
384
385 ```
386 > s
387 ```
388
389 Next step:
390
391 ```
392 > n
393 ```
394
395 Continue:
396
397 ```
398 > c
399 ```
400
401 Up/down in stacktrace:
402
403 ```
404 > up
405 > down
406 ```
407
408
409 ### Debug on Windows <a id="development-debug-windows"></a>
410
411
412 Whenever the application crashes, the Windows error reporting (WER) can be [configured](https://docs.microsoft.com/en-gb/windows/win32/wer/collecting-user-mode-dumps)
413 to create user-mode dumps.
414
415
416 Tail the log file with Powershell:
417
418 ```
419 Get-Content .\icinga2.log -tail 10 -wait
420 ```
421
422 ## Test Icinga 2 <a id="development-tests"></a>
423
424 ### Snapshot Packages (Nightly Builds) <a id="development-tests-snapshot-packages"></a>
425
426 Icinga provides snapshot packages as nightly builds from [Git master](https://github.com/icinga/icinga2).
427
428 These packages contain development code which should be considered "work in progress".
429 While developers ensure that tests are running fine with CI actions on PRs,
430 things might break, or changes are not yet documented in the changelog.
431
432 You can help the developers and test the snapshot packages, e.g. when larger
433 changes or rewrites are taking place for a new major version. Your feedback
434 is very much appreciated.
435
436 Snapshot packages are available for all supported platforms including
437 Linux and Windows and can be obtained from [https://packages.icinga.com](https://packages.icinga.com).
438
439 The [Vagrant boxes](https://github.com/Icinga/icinga-vagrant) also use
440 the Icinga snapshot packages to allow easier integration tests. It is also
441 possible to use Docker with base OS images and installing the snapshot
442 packages.
443
444 If you encounter a problem, please [open a new issue](https://github.com/Icinga/icinga2/issues/new/choose)
445 on GitHub and mention that you're testing the snapshot packages.
446
447 #### RHEL/CentOS <a id="development-tests-snapshot-packages-rhel"></a>
448
449 2.11+ requires the [EPEL repository](02-installation.md#package-repositories-rhel-epel) for Boost 1.66+.
450
451 In addition to that, the `icinga-rpm-release` package already provides the `icinga-snapshot-builds`
452 repository but it is disabled by default.
453
454 ```
455 yum -y install https://packages.icinga.com/epel/icinga-rpm-release-7-latest.noarch.rpm
456 yum -y install epel-release
457 yum makecache
458
459 yum install --enablerepo=icinga-snapshot-builds icinga2
460 ```
461
462 #### Debian <a id="development-tests-snapshot-packages-debian"></a>
463
464 2.11+ requires Boost 1.66+ which either is provided by the OS, backports or Icinga stable repositories.
465 It is advised to configure both Icinga repositories, stable and snapshot and selectively
466 choose the repository with the `-t` flag on `apt-get install`.
467
468 ```
469 apt-get update
470 apt-get -y install apt-transport-https wget gnupg
471
472 wget -O - https://packages.icinga.com/icinga.key | apt-key add -
473
474 DIST=$(awk -F"[)(]+" '/VERSION=/ {print $2}' /etc/os-release); \
475  echo "deb https://packages.icinga.com/debian icinga-${DIST} main" > \
476  /etc/apt/sources.list.d/${DIST}-icinga.list
477  echo "deb-src https://packages.icinga.com/debian icinga-${DIST} main" >> \
478  /etc/apt/sources.list.d/${DIST}-icinga.list
479
480 DIST=$(awk -F"[)(]+" '/VERSION=/ {print $2}' /etc/os-release); \
481  echo "deb http://packages.icinga.com/debian icinga-${DIST}-snapshots main" > \
482  /etc/apt/sources.list.d/${DIST}-icinga-snapshots.list
483  echo "deb-src http://packages.icinga.com/debian icinga-${DIST}-snapshots main" >> \
484  /etc/apt/sources.list.d/${DIST}-icinga-snapshots.list
485
486 apt-get update
487 ```
488
489 On Debian Stretch, you'll also need to add Debian Backports.
490
491 ```
492 DIST=$(awk -F"[)(]+" '/VERSION=/ {print $2}' /etc/os-release); \
493  echo "deb https://deb.debian.org/debian ${DIST}-backports main" > \
494  /etc/apt/sources.list.d/${DIST}-backports.list
495
496 apt-get update
497 ```
498
499 Then install the snapshot packages.
500
501 ```
502 DIST=$(awk -F"[)(]+" '/VERSION=/ {print $2}' /etc/os-release); \
503 apt-get install -t icinga-${DIST}-snapshots icinga2
504 ```
505
506 #### Ubuntu <a id="development-tests-snapshot-packages-ubuntu"></a>
507
508 ```
509 apt-get update
510 apt-get -y install apt-transport-https wget gnupg
511
512 wget -O - https://packages.icinga.com/icinga.key | apt-key add -
513
514 . /etc/os-release; if [ ! -z ${UBUNTU_CODENAME+x} ]; then DIST="${UBUNTU_CODENAME}"; else DIST="$(lsb_release -c| awk '{print $2}')"; fi; \
515  echo "deb https://packages.icinga.com/ubuntu icinga-${DIST} main" > \
516  /etc/apt/sources.list.d/${DIST}-icinga.list
517  echo "deb-src https://packages.icinga.com/ubuntu icinga-${DIST} main" >> \
518  /etc/apt/sources.list.d/${DIST}-icinga.list
519
520 . /etc/os-release; if [ ! -z ${UBUNTU_CODENAME+x} ]; then DIST="${UBUNTU_CODENAME}"; else DIST="$(lsb_release -c| awk '{print $2}')"; fi; \
521  echo "deb https://packages.icinga.com/ubuntu icinga-${DIST}-snapshots main" > \
522  /etc/apt/sources.list.d/${DIST}-icinga-snapshots.list
523  echo "deb-src https://packages.icinga.com/ubuntu icinga-${DIST}-snapshots main" >> \
524  /etc/apt/sources.list.d/${DIST}-icinga-snapshots.list
525
526 apt-get update
527 ```
528
529 Then install the snapshot packages.
530
531 ```
532 . /etc/os-release; if [ ! -z ${UBUNTU_CODENAME+x} ]; then DIST="${UBUNTU_CODENAME}"; else DIST="$(lsb_release -c| awk '{print $2}')"; fi; \
533 apt-get install -t icinga-${DIST}-snapshots icinga2
534 ```
535
536 #### SLES <a id="development-tests-snapshot-packages-sles"></a>
537
538 The required Boost packages are provided with the stable release repository.
539
540 ```
541 rpm --import https://packages.icinga.com/icinga.key
542
543 zypper ar https://packages.icinga.com/SUSE/ICINGA-release.repo
544 zypper ref
545
546 zypper ar https://packages.icinga.com/SUSE/ICINGA-snapshot.repo
547 zypper ref
548 ```
549
550 Selectively install the snapshot packages using the `-r` parameter.
551
552 ```
553 zypper in -r icinga-snapshot-builds icinga2
554 ```
555
556
557 ### Unit Tests <a id="development-tests-unit"></a>
558
559 Build the binaries and run the tests.
560
561
562 ```
563 make -j4 -C debug
564 make test -C debug
565 ```
566
567 Run a specific boost test:
568
569 ```
570 debug/Bin/Debug/boosttest-test-base --run_test=remote_url
571 ```
572
573
574
575 ## Develop Icinga 2 <a id="development-develop"></a>
576
577 Icinga 2 can be built on many platforms such as Linux, Unix and Windows.
578 There are limitations in terms of support, e.g. Windows is only supported for agents,
579 not a full-featured master or satellite.
580
581 Before you start with actual development, there is a couple of pre-requisites.
582
583 ### Preparations <a id="development-develop-prepare"></a>
584
585 #### Choose your Editor <a id="development-develop-choose-editor"></a>
586
587 Icinga 2 can be developed with your favorite editor. Icinga developers prefer
588 these tools:
589
590 - vim
591 - CLion (macOS, Linux)
592 - MS Visual Studio (Windows)
593 - Atom
594
595 Editors differ on the functionality. The more helpers you get for C++ development,
596 the faster your development workflow will be.
597
598 #### Get to know the architecture <a id="development-develop-get-to-know-the-architecture"></a>
599
600 Icinga 2 can run standalone or in distributed environments. It contains a whole lot
601 more than a simple check execution engine.
602
603 Read more about it in the [Technical Concepts](19-technical-concepts.md#technical-concepts) chapter.
604
605 #### Get to know the code <a id="development-develop-get-to-know-the-code"></a>
606
607 First off, you really need to know C++ and portions of C++11 and the boost libraries.
608 Best is to start with a book or online tutorial to get into the basics.
609 Icinga developers gained their knowledge through studies, training and self-teaching
610 code by trying it out and asking senior developers for guidance.
611
612 Here's a few books we can recommend:
613
614 * [Accelerated C++: Practical Programming by Example](https://www.amazon.com/Accelerated-C-Practical-Programming-Example/dp/020170353X) (Andrew Koenig, Barbara E. Moo)
615 * [Effective C++](https://www.amazon.com/Effective-Specific-Improve-Programs-Designs/dp/0321334876) (Scott Meyers)
616 * [Boost C++ Application Development Cookbook - Second Edition: Recipes to simplify your application development](https://www.amazon.com/dp/1787282244/ref=cm_sw_em_r_mt_dp_U_dN1OCbERS00EQ) (Antony Polukhin)
617 * [Der C++ Programmierer](https://www.amazon.de/Programmierer-lernen-Professionell-anwenden-L%C3%B6sungen/dp/3446416447), German (Ulrich Breymann)
618 * [C++11 programmieren](https://www.amazon.de/gp/product/3836217325/), German (Torsten T. Will)
619
620 In addition, it is a good bet to also know SQL when diving into backend development.
621
622 * [SQL Performance Explained](https://www.amazon.de/gp/product/3950307826/) (Markus Winand)
623
624 Last but not least, if you are developing on Windows, get to know the internals about services and the Win32 API.
625
626 ### Design Patterns <a id="development-develop-design-patterns"></a>
627
628 Icinga 2 heavily relies on object-oriented programming and encapsulates common
629 functionality into classes and objects. It also uses modern programming techniques
630 to e.g. work with shared pointer memory management.
631
632 Icinga 2 consists of libraries bundled into the main binary. Therefore you'll
633 find many code parts in the `lib/` directory wheras the actual application is
634 built from `icinga-app/`. Accompanied with Icinga 2, there's the Windows plugins
635 which are standalone and compiled from `plugins/`.
636
637 Library        | Description
638 ---------------|------------------------------------
639 base           | Objects, values, types, streams, tockets, TLS, utilities, etc.
640 config         | Configuration compiler, expressions, etc.
641 cli            | CLI (sub) commands and helpers.
642 icinga         | Icinga specific objects and event handling.
643 remote         | Cluster and HTTP client/server and REST API related code.
644 checker        | Checker feature, check scheduler.
645 notification   | Notification feature, notification scheduler.
646 methods        | Command execution methods, plugins and built-in checks.
647 perfdata       | Performance data related, including Graphite, Elastic, etc.
648 db\_ido        | IDO database abstraction layer.
649 db\_ido\_mysql | IDO database driver for MySQL.
650 db\_ido\_pgsql | IDO database driver for PgSQL.
651 mysql\_shin    | Library stub for linking against the MySQL client libraries.
652 pgsql\_shim    | Library stub for linking against the PgSQL client libraries.
653
654 #### Class Compiler <a id="development-develop-design-patterns-class-compiler"></a>
655
656 Another thing you will recognize are the `.ti` files which are compiled
657 by our own class compiler into actual source code. The meta language allows
658 developers to easily add object attributes and specify their behaviour.
659
660 Some object attributes need to be stored over restarts in the state file
661 and therefore have the `state` attribute set. Others are treated as `config`
662 attribute and automatically get configuration validation functions created.
663 Hidden or read-only REST API attributes are marked with `no_user_view` and
664 `no_user_modify`.
665
666 The most beneficial thing are getters and setters being generated. The actual object
667 inherits from `ObjectImpl<TYPE>` and therefore gets them "for free".
668
669 Example:
670
671 ```
672 vim lib/perfdata/gelfwriter.ti
673
674   [config] enable_tls;
675
676 vim lib/perfdata/gelfwriter.cpp
677
678     if (GetEnableTls()) {
679 ```
680
681 The logic is hidden in `tools/mkclass/` in case you want to learn more about it.
682 The first steps during CMake & make also tell you about code generation.
683
684 ### Build Tools <a id="development-develop-builds-tools"></a>
685
686 #### CMake <a id="development-develop-builds-cmake"></a>
687
688 In its early development stages in 2012, Icinga 2 was built with autoconf/automake
689 and separate Windows project files. We've found this very fragile, and have changed
690 this into CMake as our build tool.
691
692 The most common benefits:
693
694 * Everything is described in CMakeLists.txt in each directory
695 * CMake only needs to know that a sub directory needs to be included.
696 * The global CMakeLists.txt acts as main entry point for requirement checks and library/header includes.
697 * Separate binary build directories, the actual source tree stays clean.
698 * CMake automatically generates a Visual Studio project file `icinga2.sln` on Windows.
699
700 #### Unity Builds <a id="development-develop-builds-unity-builds"></a>
701
702 Another thing you should be aware of: Unity builds on and off.
703
704 Typically, we already use caching mechanisms to reduce recompile time with ccache.
705 For release builds, there's always a new build needed as the difference is huge compared
706 to a previous (major) release.
707
708 Therefore we've invented the Unity builds, which basically concatenates all source files
709 into one big library source code file. The compiler then doesn't need to load the many small
710 files but compiles and links this huge one.
711
712 Unity builds require more memory which is why you should disable them for development
713 builds in small sized VMs (Linux, Windows) and also Docker containers.
714
715 There's a couple of header files which are included everywhere. If you touch/edit them,
716 the cache is invalidated and you need to recompile a lot more files then. `base/utility.hpp`
717 and `remote/zone.hpp` are good candidates for this.
718
719 ### Unit Tests <a id="development-develop-tests"></a>
720
721 New functions and classes must implement new unit tests. Whenever
722 you decide to add new functions, ensure that you don't need a complex
723 mock or runtime attributes in order to test them. Better isolate
724 code into function interfaces which can be invoked in the Boost tests
725 framework.
726
727 Look into the existing tests in the [test/](https://github.com/Icinga/icinga2/tree/master/test) directory
728 and adopt new test cases.
729
730 Specific tests require special time windows, they are only
731 enabled in debug builds for developers. This is the case e.g.
732 for testing the flapping algorithm with expected state change
733 detection at a specific point from now.
734
735
736 ### Style Guide <a id="development-develop-styleguide"></a>
737
738 Overview of project files:
739
740 File Type      | File Name/Extension | Description
741 ---------------|---------------------|-----------------------------
742 Header         | .hpp                | Classes, enums, typedefs inside the icinga Namespace.
743 Source         | .cpp                | Method implementation for class functions, static/global variables.
744 CMake          | CMakeLists.txt      | Build configuration, source and header file references.
745 CMake Source   | .cmake              | Source/Header files generated from CMake placeholders.
746 ITL/conf.d     | .conf               | Template library and example files as configuration
747 Class Compiler | .ti                 | Object classes in our own language, generates source code as `<filename>-ti.{c,h}pp`.
748 Lexer/Parser   | .ll, .yy            | Flex/Bison code generated into source code from CMake builds.
749 Docs           | .md                 | Markdown docs and READMEs.
750
751 Anything else are additional tools and scripts for developers and build systems.
752
753 All files must include the copyright header. We don't use the
754 current year as this implies yearly updates we don't want.
755
756 Depending on the file type, this must be a comment.
757
758 ```
759 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
760
761 # Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
762 ```
763
764 #### Code Formatting <a id="development-develop-code-formatting"></a>
765
766 **Tabs instead of spaces.** Inside Visual Studio, choose to keep tabs instead of
767 spaces. Tabs should use 4 spaces indent by default, depending on your likings.
768
769 We follow the clang format, with some exceptions.
770
771 - Curly braces for functions and classes always start at a new line.
772
773 ```
774 String ConfigObjectUtility::EscapeName(const String& name)
775 {
776 //...
777 }
778
779 String ConfigObjectUtility::CreateObjectConfig(const Type::Ptr& type, const String& fullName,
780         bool ignoreOnError, const Array::Ptr& templates, const Dictionary::Ptr& attrs)
781 {
782 //...
783 }
784 ```
785
786 - Too long lines break at a parameter, the new line needs a tab indent.
787
788 ```
789         static String CreateObjectConfig(const Type::Ptr& type, const String& fullName,
790                 bool ignoreOnError, const Array::Ptr& templates, const Dictionary::Ptr& attrs);
791 ```
792
793 - Conditions require curly braces if it is not a single if with just one line.
794
795
796 ```
797         if (s == "OK") {
798                 //...
799         } else {
800                 //...
801         }
802
803         if (!n)
804                 return;
805 ```
806
807 - There's a space between `if` and the opening brace `(`. Also after the closing brace `)` and opening curly brace `{`.
808 - Negation with `!` doesn't need an extra space.
809 - Else branches always start in the same line after the closing curly brace.
810
811
812 #### Code Comments <a id="development-develop-code-comments"></a>
813
814 Add comments wherever you think that another developer will have a hard
815 time to understand the complex algorithm. Or you might have forgotten
816 it in a year and struggle again. Also use comments to highlight specific
817 stages in a function. Generally speaking, make things easier for the
818 team and external contributors.
819
820 Comments can also be used to mark additional references and TODOs.
821 If there is a specific GitHub issue or discussion going on,
822 use that information as a summary and link over to it on purpose.
823
824 - Single line comments may use `//` or `/* ... */`
825 - Multi line comments must use this format:
826
827 ```
828 /* Ensure to check for XY
829  * This relies on the fact that ABC has been set before.
830  */
831 ```
832
833 #### Function Docs <a id="development-develop-function-docs"></a>
834
835 Function header documentation must be added. The current code basis
836 needs rework, future functions must provide this.
837
838 Editors like CLion or Visual Studio allow you to type `/**` followed
839 by Enter and generate the skeleton from the implemented function.
840
841 Add a short summary in the first line about the function's purpose.
842 Edit the param section with short description on their intention.
843 The `return` value should describe the value type and additional details.
844
845 Example:
846
847 ```
848 /**
849  * Reads a message from the connected peer.
850  *
851  * @param stream ASIO TLS Stream
852  * @param yc Yield Context for ASIO
853  * @param maxMessageLength maximum size of bytes read.
854  *
855  * @return A JSON string
856  */
857 String JsonRpc::ReadMessage(const std::shared_ptr<AsioTlsStream>& stream, boost::asio::yield_context yc, ssize_t maxMessageLength)
858 ```
859
860 While we can generate code docs from it, the main idea behind it is
861 to provide on-point docs to fully understand all parameters and the
862 function's purpose in the same spot.
863
864
865 #### Header <a id="development-develop-styleguide-header"></a>
866
867 Only include other headers which are mandatory for the header definitions.
868 If the source file requires additional headers, add them there to avoid
869 include loops.
870
871 The included header order is important.
872
873 - First, include the library header `i2-<libraryname>.hpp`, e.g. `i2-base.hpp`.
874 - Second, include all headers from Icinga itself, e.g. `remote/apilistener.hpp`. `base` before `icinga` before `remote`, etc.
875 - Third, include third-party and external library headers, e.g. openssl and boost.
876 - Fourth, include STL headers.
877
878 #### Source <a id="development-develop-styleguide-source"></a>
879
880 The included header order is important.
881
882 - First, include the header whose methods are implemented.
883 - Second, include all headers from Icinga itself, e.g. `remote/apilistener.hpp`. `base` before `icinga` before `remote`, etc.
884 - Third, include third-party and external library headers, e.g. openssl and boost.
885 - Fourth, include STL headers.
886
887 Always use an empty line after the header include parts.
888
889 #### Namespace <a id="development-develop-styleguide-namespace"></a>
890
891 The icinga namespace is used globally, as otherwise we would need to write `icinga::Utility::FormatDateTime()`.
892
893 ```
894 using namespace icinga;
895 ```
896
897 Other namespaces must be declared in the scope they are used. Typically
898 this is inside the function where `boost::asio` and variants would
899 complicate the code.
900
901 ```
902         namespace ssl = boost::asio::ssl;
903
904         auto context (std::make_shared<ssl::context>(ssl::context::sslv23));
905 ```
906
907 #### Functions <a id="development-develop-styleguide-functions"></a>
908
909 Ensure to pass values and pointers as const reference. By default, all
910 values will be copied into the function scope, and we want to avoid this
911 wherever possible.
912
913 ```
914 std::vector<EventQueue::Ptr> EventQueue::GetQueuesForType(const String& type)
915 ```
916
917 C++ only allows to return a single value. This can be abstracted with
918 returning a specific class object, or with using a map/set. Array and
919 Dictionary objects increase the memory footprint, use them only where needed.
920
921 A common use case for Icinga value types is where a function can return
922 different values - an object, an array, a boolean, etc. This happens in the
923 inner parts of the config compiler expressions, or config validation.
924
925 The function caller is responsible to determine the correct value type
926 and handle possible errors.
927
928 Specific algorithms may require to populate a list, which can be passed
929 by reference to the function. The inner function can then append values.
930 Do not use a global shared resource here, unless this is locked by the caller.
931
932
933 #### Conditions and Cases <a id="development-develop-styleguide-conditions"></a>
934
935 Prefer if-else-if-else branches. When integers are involved,
936 switch-case statements increase readability. Don't forget about `break` though!
937
938 Avoid using ternary operators where possible. Putting a condition
939 after an assignment complicates reading the source. The compiler
940 optimizes this anyways.
941
942 Wrong:
943
944 ```
945         int res = s == "OK" ? 0 : s == "WARNING" ? 1;
946
947         return res;
948 ```
949
950 Better:
951
952 ```
953         int res = 3;
954
955         if (s == "OK") {
956                 res = 0;
957         } else if (s == "WARNING") {
958                 res = 1;
959         }
960 ```
961
962 Even better: Create a lookup map instead of if branches. The complexity
963 is reduced to O(log(n)).
964
965 ```
966         std::map<String, unsigned int> stateMap = {
967                 { "OK", 1 },
968                 { "WARNING", 2 }
969         }
970
971         auto it = stateMap.find(s);
972
973         if (it == stateMap.end()) {
974                 return 3
975         }
976
977         return it.second;
978 ```
979
980 The code is not as short as with a ternary operator, but one can re-use
981 this design pattern for other generic definitions with e.g. moving the
982 lookup into a utility class.
983
984 Once a unit test is written, everything works as expected in the future.
985
986 #### Locks and Guards <a id="development-develop-locks-guards"></a>
987
988 Lock access to resources where multiple threads can read and write.
989 Icinga objects can be locked with the `ObjectLock` class.
990
991 Object locks and guards must be limited to the scope where they are needed. Otherwise we could create dead locks.
992
993 ```
994         {
995                 ObjectLock olock(frame.Locals);
996                 for (const Dictionary::Pair& kv : frame.Locals) {
997                         AddSuggestion(matches, word, kv.first);
998                 }
999         }
1000 ```
1001
1002 #### Objects and Pointers <a id="development-develop-objects-pointers"></a>
1003
1004 Use shared pointers for objects. Icinga objects implement the `Ptr`
1005 typedef returning an `intrusive_ptr` for the class object (object.hpp).
1006 This also ensures reference counting for the object's lifetime.
1007
1008 Use raw pointers with care!
1009
1010 Some methods and classes require specific shared pointers, especially
1011 when interacting with the Boost library.
1012
1013 #### Value Types <a id="development-develop-styleguide-value-types"></a>
1014
1015 Icinga has its own value types. These provide methods to allow
1016 generic serialization into JSON for example, and other type methods
1017 which are made available in the DSL too.
1018
1019 - Always use `String` instead of `std::string`. If you need a C-string, use the `CStr()` method.
1020 - Avoid casts and rather use the `Convert` class methods.
1021
1022 ```
1023         double s = static_cast<double>(v); //Wrong
1024
1025         double s = Convert::ToDouble(v);   //Correct, ToDouble also provides overloads with different value types
1026 ```
1027
1028 - Prefer STL containers for internal non-user interfaces. Icinga value types add a small overhead which may decrease performance if e.g. the function is called 100k times.
1029 - `Array::FromVector` and variants implement conversions, use them.
1030
1031 #### Utilities <a id="development-develop-styleguide-utilities"></a>
1032
1033 Don't re-invent the wheel. The `Utility` class provides
1034 many helper functions which allow you e.g. to format unix timestamps,
1035 search in filesystem paths.
1036
1037 Also inspect the Icinga objects, they also provide helper functions
1038 for formatting, splitting strings, joining arrays into strings, etc.
1039
1040 #### Libraries <a id="development-develop-styleguide-libraries"></a>
1041
1042 2.11 depends on [Boost 1.66](https://www.boost.org/doc/libs/1_66_0/).
1043 Use the existing libraries and header-only includes
1044 for this specific version.
1045
1046 Note: Prefer C++11 features where possible, e.g. std::atomic and lambda functions.
1047
1048 General:
1049
1050 - [exception](https://www.boost.org/doc/libs/1_66_0/libs/exception/doc/boost-exception.html) (header only)
1051 - [algorithm](https://www.boost.org/doc/libs/1_66_0/libs/algorithm/doc/html/index.html) (header only)
1052 - [lexical_cast](https://www.boost.org/doc/libs/1_66_0/doc/html/boost_lexical_cast.html) (header only)
1053 - [regex](https://www.boost.org/doc/libs/1_66_0/libs/regex/doc/html/index.html)
1054 - [uuid](https://www.boost.org/doc/libs/1_66_0/libs/uuid/doc/uuid.html) (header only)
1055 - [range](https://www.boost.org/doc/libs/1_66_0/libs/range/doc/html/index.html) (header only)
1056 - [variant](https://www.boost.org/doc/libs/1_66_0/doc/html/variant.html) (header only)
1057 - [multi_index](https://www.boost.org/doc/libs/1_66_0/libs/multi_index/doc/index.html) (header only)
1058 - [function_types](https://www.boost.org/doc/libs/1_66_0/libs/function_types/doc/html/index.html) (header only)
1059 - [circular_buffer](https://www.boost.org/doc/libs/1_66_0/doc/html/circular_buffer.html) (header only)
1060 - [math](https://www.boost.org/doc/libs/1_66_0/libs/math/doc/html/index.html) (header only)
1061
1062 Events and Runtime:
1063
1064 - [system](https://www.boost.org/doc/libs/1_66_0/libs/system/doc/index.html)
1065 - [thread](https://www.boost.org/doc/libs/1_66_0/doc/html/thread.html)
1066 - [signals2](https://www.boost.org/doc/libs/1_66_0/doc/html/signals2.html) (header only)
1067 - [program_options](https://www.boost.org/doc/libs/1_66_0/doc/html/program_options.html)
1068 - [date_time](https://www.boost.org/doc/libs/1_66_0/doc/html/date_time.html)
1069 - [filesystem](https://www.boost.org/doc/libs/1_66_0/libs/filesystem/doc/index.htm)
1070
1071 Network I/O:
1072
1073 - [asio](https://www.boost.org/doc/libs/1_66_0/doc/html/boost_asio.html) (header only)
1074 - [beast](https://www.boost.org/doc/libs/1_66_0/libs/beast/doc/html/index.html) (header only)
1075 - [coroutine](https://www.boost.org/doc/libs/1_66_0/libs/coroutine/doc/html/index.html)
1076 - [context](https://www.boost.org/doc/libs/1_66_0/libs/context/doc/html/index.html)
1077
1078 Consider abstracting their usage into `*utility.{c,h}pp` files with
1079 wrapping existing Icinga types. That also allows later changes without
1080 rewriting large code parts.
1081
1082 > **Note**
1083 >
1084 > A new Boost library should be explained in a PR and discussed with the team.
1085 >
1086 > This requires package dependency changes.
1087
1088 If you consider an external library or code to be included with Icinga, the following
1089 requirements must be fulfilled:
1090
1091 - License is compatible with GPLv2+. Boost license, MIT works, Apache is not.
1092 - C++11 is supported, C++14 or later doesn't work
1093 - Header only implementations are preferred, external libraries require packages on every distribution.
1094 - No additional frameworks, Boost is the only allowed.
1095 - The code is proven to be robust and the GitHub repository is alive, or has 1k+ stars. Good libraries also provide a user list, if e.g. Ceph is using it, this is a good candidate.
1096
1097
1098 #### Log <a id="development-develop-styleguide-log"></a>
1099
1100 Icinga allows the user to configure logging backends, e.g. syslog or file.
1101
1102 Any log message inside the code must use the `Log()` function.
1103
1104 - The first parameter is the severity level, use them with care.
1105 - The second parameter defines the location/scope where the log
1106 happened. Typically we use the class name here, to better analyse
1107 the logs the user provide in GitHub issues and on the community
1108 channels.
1109 - The third parameter takes a log message string
1110
1111 If the message string needs to be computed from existing values,
1112 everything must be converted to the String type beforehand.
1113 This conversion for every value is very expensive which is why
1114 we try to avoid it.
1115
1116 Instead, use Log() with the shift operator where everything is written
1117 on the stream and conversions are explicitly done with templates
1118 in the background.
1119
1120 The trick here is that the Log object is destroyed immediately
1121 after being constructed once. The destructor actually
1122 evaluates the values and sends it to registers loggers.
1123
1124 Since flushing the stream every time a log entry occurs is
1125 very expensive, a timer takes care of flushing the stream
1126 every second.
1127
1128 > **Tip**
1129 >
1130 > If logging stopped, the flush timer thread may be dead.
1131 > Inspect that with gdb/lldb.
1132
1133 Avoid log messages which could irritate the user. During
1134 implementation, developers can change log levels to better
1135 see what's going one, but remember to change this back to `debug`
1136 or remove it entirely.
1137
1138
1139 #### Goto <a id="development-develop-styleguide-goto"></a>
1140
1141 Avoid using `goto` statements. There are rare occasions where
1142 they are allowed:
1143
1144 - The code would become overly complicated within nested loops and conditions.
1145 - Event processing and C interfaces.
1146 - Question/Answer loops within interactive CLI commands.
1147
1148 #### Typedef and Auto Keywords <a id="development-develop-styleguide-typedef-auto"></a>
1149
1150 Typedefs allow developers to use shorter names for specific types,
1151 classes and structs.
1152
1153 ```
1154         typedef std::map<String, std::shared_ptr<NamespaceValue> >::iterator Iterator;
1155 ```
1156
1157 These typedefs should be part of the Class definition in the header,
1158 or may be defined in the source scope where they are needed.
1159
1160 Avoid declaring global typedefs, unless necessary.
1161
1162 Using the `auto` keyword allows to ignore a specific value type.
1163 This comes in handy with maps/sets where no specific access
1164 is required.
1165
1166 The following example iterates over a map returned from `GetTypes()`.
1167
1168 ```
1169         for (const auto& kv : GetTypes()) {
1170                 result.insert(kv.second);
1171         }
1172 ```
1173
1174 The long example would require us to define a map iterator, and a slightly
1175 different algorithm.
1176
1177 ```
1178         typedef std::map<String, DbType::Ptr> TypeMap;
1179         typedef std::map<String, DbType::Ptr>::const_iterator TypeMapIterator;
1180
1181         TypeMap types = GetTypes();
1182
1183         for (TypeMapIterator it = types.begin(); it != types.end(); it++) {
1184                 result.insert(it.second);
1185         }
1186 ```
1187
1188 We could also use a pair here, but requiring to know
1189 the specific types of the map keys and values.
1190
1191 ```
1192         typedef std::pair<String, DbType::Ptr> kv_pair;
1193
1194         for (const kv_pair& kv : GetTypes()) {
1195                 result.insert(kv.second);
1196         }
1197 ```
1198
1199 After all, `auto` shortens the code and one does not always need to know
1200 about the specific types. Function documentation for `GetTypes()` is
1201 required though.
1202
1203
1204
1205 #### Whitespace Cleanup <a id="development-develop-choose-editor-whitespaces"></a>
1206
1207 Patches must be cleaned up and follow the indent style (tabs instead of spaces).
1208 You should also remove any trailing whitespaces.
1209
1210 `git diff` allows to highlight such.
1211
1212 ```
1213 vim $HOME/.gitconfig
1214
1215 [color "diff"]
1216         whitespace = red reverse
1217 [core]
1218         whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol
1219 ```
1220
1221 `vim` also can match these and visually alert you to remove them.
1222
1223 ```
1224 vim $HOME/.vimrc
1225
1226 highlight ExtraWhitespace ctermbg=red guibg=red
1227 match ExtraWhitespace /\s\+$/
1228 autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
1229 autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
1230 autocmd InsertLeave * match ExtraWhitespace /\s\+$/
1231 autocmd BufWinLeave * call clearmatches()
1232 ```
1233
1234
1235 ## Development Environment <a id="development-environment"></a>
1236
1237 ### Linux Dev Environment <a id="development-linux-dev-env"></a>
1238
1239 Based on CentOS 7, we have an early draft available inside the Icinga Vagrant boxes:
1240 [centos7-dev](https://github.com/Icinga/icinga-vagrant/tree/master/centos7-dev).
1241
1242 If you're compiling Icinga 2 natively without any virtualization layer in between,
1243 this usually is faster. This is also the reason why developers on macOS prefer native builds
1244 over Linux or Windows VMs. Don't forget to test the actual code on Linux later! Socket specific
1245 stuff like `epoll` is not available on Unix kernels.
1246
1247 Depending on your workstation and environment, you may either develop and run locally,
1248 use a container deployment pipeline or put everything in a high end resource remote VM.
1249
1250 Fork https://github.com/Icinga/icinga2 into your own repository, e.g. `https://github.com/dnsmichi/icinga2`.
1251
1252 Create two build directories for different binary builds.
1253
1254 * `debug` contains the debug build binaries. They contain more debug information and run tremendously slower than release builds from packages. Don't use them for benchmarks.
1255 * `release` contains the release build binaries, as you would install them on a live system. This helps comparing specific scenarios for race conditions and more.
1256
1257 ```
1258 mkdir -p release debug
1259 ```
1260
1261 Proceed with the specific distribution examples below.
1262
1263 * [CentOS 7](21-development.md#development-linux-dev-env-centos)
1264 * [Debian 9](21-development.md#development-linux-dev-env-debian)
1265
1266
1267 #### CentOS 7 <a id="development-linux-dev-env-centos"></a>
1268
1269 ```
1270 yum -y install gdb vim git bash-completion htop
1271
1272 yum -y install rpmdevtools ccache \
1273  cmake make gcc-c++ flex bison \
1274  openssl-devel boost169-devel systemd-devel \
1275  mysql-devel postgresql-devel libedit-devel \
1276  libstdc++-devel
1277
1278 groupadd icinga
1279 groupadd icingacmd
1280 useradd -c "icinga" -s /sbin/nologin -G icingacmd -g icinga icinga
1281
1282 ln -s /bin/ccache /usr/local/bin/gcc
1283 ln -s /bin/ccache /usr/local/bin/g++
1284
1285 git clone https://github.com/icinga/icinga2.git && cd icinga2
1286 ```
1287
1288 The debug build binaries contain specific code which runs
1289 slower but allows for better debugging insights.
1290
1291 For benchmarks, change `CMAKE_BUILD_TYPE` to `RelWithDebInfo` and
1292 build inside the `release` directory.
1293
1294 First, off export some generics for Boost.
1295
1296 ```
1297 export I2_BOOST="-DBoost_NO_BOOST_CMAKE=TRUE -DBoost_NO_SYSTEM_PATHS=TRUE -DBOOST_LIBRARYDIR=/usr/lib64/boost169 -DBOOST_INCLUDEDIR=/usr/include/boost169 -DBoost_ADDITIONAL_VERSIONS='1.69;1.69.0'"
1298 ```
1299
1300 Second, add the prefix path to it.
1301
1302 ```
1303 export I2_GENERIC="$I2_BOOST -DCMAKE_INSTALL_PREFIX=/usr/local/icinga2"
1304 ```
1305
1306 Third, define the two build types with their specific CMake variables.
1307
1308 ```
1309 export I2_DEBUG="-DCMAKE_BUILD_TYPE=Debug -DICINGA2_UNITY_BUILD=OFF $I2_GENERIC"
1310 export I2_RELEASE="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DICINGA2_WITH_TESTS=ON -DICINGA2_UNITY_BUILD=ON $I2_GENERIC"
1311 ```
1312
1313 Fourth, depending on your likings, you may add a bash alias for building,
1314 or invoke the commands inside:
1315
1316 ```
1317 alias i2_debug="cd /root/icinga2; mkdir -p debug; cd debug; cmake $I2_DEBUG ..; make -j2; sudo make -j2 install; cd .."
1318 alias i2_release="cd /root/icinga2; mkdir -p release; cd release; cmake $I2_RELEASE ..; make -j2; sudo make -j2 install; cd .."
1319 ```
1320
1321 This is taken from the [centos7-dev](https://github.com/Icinga/icinga-vagrant/tree/master/centos7-dev) Vagrant box.
1322
1323
1324 The source installation doesn't set proper permissions, this is
1325 handled in the package builds which are officially supported.
1326
1327 ```
1328 chown -R icinga:icinga /usr/local/icinga2/var/
1329
1330 /usr/local/icinga2/lib/icinga2/prepare-dirs /usr/local/icinga2/etc/sysconfig/icinga2
1331 /usr/local/icinga2/sbin/icinga2 api setup
1332 vim /usr/local/icinga2/etc/icinga2/conf.d/api-users.conf
1333
1334 gdb --args /usr/local/icinga2/lib/icinga2/sbin/icinga2 daemon
1335 ```
1336
1337 #### Debian 9 <a id="development-linux-dev-env-debian"></a>
1338
1339 ```
1340 apt-get -y install gdb vim git cmake make ccache build-essential libssl-dev libboost-all-dev bison flex default-libmysqlclient-dev libpq-dev libedit-dev monitoring-plugins
1341
1342 ln -s /usr/bin/ccache /usr/local/bin/gcc
1343 ln -s /usr/bin/ccache /usr/local/bin/g++
1344
1345 groupadd icinga
1346 groupadd icingacmd
1347 useradd -c "icinga" -s /sbin/nologin -G icingacmd -g icinga icinga
1348
1349 git clone https://github.com/icinga/icinga2.git && cd icinga2
1350
1351 mkdir debug release
1352 cd debug
1353 cmake .. -DCMAKE_BUILD_TYPE=Debug -DICINGA2_UNITY_BUILD=OFF -DCMAKE_INSTALL_PREFIX=/usr/local/icinga2 -DICINGA2_PLUGINDIR=/usr/local/sbin
1354 cd ..
1355 make -j2 install -C debug
1356 ```
1357
1358
1359 ```
1360 chown -R icinga:icinga /usr/local/icinga2/var/
1361
1362 /usr/local/icinga2/lib/icinga2/prepare-dirs /usr/local/icinga2/etc/sysconfig/icinga2
1363 /usr/local/icinga2/sbin/icinga2 api setup
1364 vim /usr/local/icinga2/etc/icinga2/conf.d/api-users.conf
1365
1366 gdb --args /usr/local/icinga2/lib/icinga2/sbin/icinga2 daemon
1367 ```
1368
1369
1370 #### Ubuntu 18 Bionic <a id="development-linux-dev-env-ubuntu"></a>
1371
1372 Requires Boost packages from packages.icinga.com.
1373
1374 ```
1375 $ docker run -ti ubuntu:bionic bash
1376
1377 apt-get update
1378 apt-get -y install apt-transport-https wget gnupg
1379
1380 wget -O - https://packages.icinga.com/icinga.key | apt-key add -
1381
1382 . /etc/os-release; if [ ! -z ${UBUNTU_CODENAME+x} ]; then DIST="${UBUNTU_CODENAME}"; else DIST="$(lsb_release -c| awk '{print $2}')"; fi; \
1383  echo "deb https://packages.icinga.com/ubuntu icinga-${DIST} main" > \
1384  /etc/apt/sources.list.d/${DIST}-icinga.list
1385  echo "deb-src https://packages.icinga.com/ubuntu icinga-${DIST} main" >> \
1386  /etc/apt/sources.list.d/${DIST}-icinga.list
1387
1388 apt-get update
1389 ```
1390
1391 ```
1392 apt-get -y install gdb vim git cmake make ccache build-essential libssl-dev bison flex default-libmysqlclient-dev libpq-dev libedit-dev monitoring-plugins
1393
1394 apt-get install -y libboost1.67-icinga-all-dev
1395
1396 ln -s /usr/bin/ccache /usr/local/bin/gcc
1397 ln -s /usr/bin/ccache /usr/local/bin/g++
1398
1399 groupadd icinga
1400 groupadd icingacmd
1401 useradd -c "icinga" -s /sbin/nologin -G icingacmd -g icinga icinga
1402
1403 git clone https://github.com/icinga/icinga2.git && cd icinga2
1404
1405 mkdir debug release
1406
1407 export I2_DEB="-DBoost_NO_BOOST_CMAKE=TRUE -DBoost_NO_SYSTEM_PATHS=TRUE -DBOOST_LIBRARYDIR=/usr/lib/x86_64-linux-gnu/icinga-boost -DBOOST_INCLUDEDIR=/usr/include/icinga-boost -DCMAKE_INSTALL_RPATH=/usr/lib/x86_64-linux-gnu/icinga-boost"
1408 export I2_GENERIC="-DCMAKE_INSTALL_PREFIX=/usr/local/icinga2 -DICINGA2_PLUGINDIR=/usr/local/sbin"
1409 export I2_DEBUG="$I2_DEB $I2_GENERIC -DCMAKE_BUILD_TYPE=Debug -DICINGA2_UNITY_BUILD=OFF"
1410
1411 cd debug
1412 cmake .. $I2_DEBUG
1413 cd ..
1414 ```
1415
1416 ```
1417 make -j2 install -C debug
1418 ```
1419
1420
1421 ```
1422 chown -R icinga:icinga /usr/local/icinga2/var/
1423
1424 /usr/local/icinga2/lib/icinga2/prepare-dirs /usr/local/icinga2/etc/sysconfig/icinga2
1425 /usr/local/icinga2/sbin/icinga2 api setup
1426 vim /usr/local/icinga2/etc/icinga2/conf.d/api-users.conf
1427
1428 gdb --args /usr/local/icinga2/lib/icinga2/sbin/icinga2 daemon
1429 ```
1430
1431 ### macOS Dev Environment <a id="development-macos-dev-env"></a>
1432
1433 It is advised to use Homebrew to install required build dependencies.
1434 Macports have been reported to work as well, typically you'll get more help
1435 with Homebrew from Icinga developers.
1436
1437 The idea is to run Icinga with the current user, avoiding root permissions.
1438 This requires at least v2.11.
1439
1440 > **Note**
1441 >
1442 > This is a pure development setup for Icinga developers reducing the compile
1443 > time in contrast to VMs. There are no packages, startup scripts or dependency management involved.
1444 >
1445 > **macOS agents are not officially supported.**
1446 >
1447 > macOS uses its own TLS implementation, Icinga relies on extra OpenSSL packages
1448 > requiring updates apart from vendor security updates.
1449
1450 #### Requirements
1451
1452 Explicitly use OpenSSL 1.1.x, older versions are out of support.
1453
1454 ```
1455 brew install ccache boost cmake bison flex openssl@1.1 mysql-connector-c++ postgresql libpq
1456 ```
1457
1458 ##### ccache
1459
1460 ```
1461 sudo mkdir /opt/ccache
1462
1463 sudo ln -s `which ccache` /opt/ccache/clang
1464 sudo ln -s `which ccache` /opt/ccache/clang++
1465
1466 vim $HOME/.bash_profile
1467
1468 # ccache is managed with symlinks to avoid collision with cgo
1469 export PATH="/opt/ccache:$PATH"
1470
1471 source $HOME/.bash_profile
1472 ```
1473
1474 #### Builds
1475
1476 Icinga is built as release (optimized build for packages) and debug (more symbols and details for debugging). Debug builds
1477 typically run slower than release builds and must not be used for performance benchmarks.
1478
1479 The preferred installation prefix is `/usr/local/icinga/icinga2`. This allows to put e.g. Icinga Web 2 into the `/usr/local/icinga` directory as well.
1480
1481 ```
1482 mkdir -p release debug
1483
1484 export I2_USER=$(id -u -n)
1485 export I2_GROUP=$(id -g -n)
1486 export I2_GENERIC="-DCMAKE_INSTALL_PREFIX=/usr/local/icinga/icinga2 -DICINGA2_USER=$I2_USER -DICINGA2_GROUP=$I2_GROUP -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl@1.1/include -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl@1.1/lib/libssl.dylib -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl@1.1/lib/libcrypto.dylib -DICINGA2_PLUGINDIR=/usr/local/sbin -DICINGA2_WITH_PGSQL=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
1487 export I2_DEBUG="-DCMAKE_BUILD_TYPE=Debug -DICINGA2_UNITY_BUILD=OFF $I2_GENERIC"
1488 export I2_RELEASE="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DICINGA2_WITH_TESTS=ON -DICINGA2_UNITY_BUILD=ON $I2_GENERIC"
1489
1490 cd debug
1491 cmake $I2_DEBUG ..
1492 cd ..
1493
1494 make -j4 -C debug
1495 make -j4 install -C debug
1496 ```
1497
1498 In order to run Icinga without any path prefix, and also use Bash completion it is advised to source additional
1499 things into the local dev environment.
1500
1501 ```
1502 export PATH=/usr/local/icinga/icinga2/sbin/:$PATH
1503
1504 test -f /usr/local/icinga/icinga2/etc/bash_completion.d/icinga2 && source /usr/local/icinga/icinga2/etc/bash_completion.d/icinga2
1505 ```
1506
1507 ##### Build Aliases
1508
1509 This is derived from [dnsmichi's flavour](https://github.com/dnsmichi/dotfiles) and not generally best practice.
1510
1511 ```
1512 vim $HOME/.bash_profile
1513
1514 export I2_USER=$(id -u -n)
1515 export I2_GROUP=$(id -g -n)
1516 export I2_GENERIC="-DCMAKE_INSTALL_PREFIX=/usr/local/icinga/icinga2 -DICINGA2_USER=$I2_USER -DICINGA2_GROUP=$I2_GROUP -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl@1.1/include -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl@1.1/lib/libssl.dylib -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl@1.1/lib/libcrypto.dylib -DICINGA2_PLUGINDIR=/usr/local/sbin -DICINGA2_WITH_PGSQL=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
1517
1518 export I2_DEBUG="-DCMAKE_BUILD_TYPE=Debug -DICINGA2_UNITY_BUILD=OFF $I2_GENERIC"
1519 export I2_RELEASE="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DICINGA2_WITH_TESTS=ON -DICINGA2_UNITY_BUILD=ON $I2_GENERIC"
1520
1521 alias i2_debug="mkdir -p debug; cd debug; cmake $I2_DEBUG ..; make -j4; make -j4 install; cd .."
1522 alias i2_release="mkdir -p release; cd release; cmake $I2_RELEASE ..; make -j4; make -j4 install; cd .."
1523
1524 export PATH=/usr/local/icinga/icinga2/sbin/:$PATH
1525 test -f /usr/local/icinga/icinga2/etc/bash_completion.d/icinga2 && source /usr/local/icinga/icinga2/etc/bash_completion.d/icinga2
1526
1527
1528 source $HOME/.bash_profile
1529 ```
1530
1531 #### Permissions
1532
1533 `make install` doesn't set all required permissions, override this.
1534
1535 ```
1536 chown -R $I2_USER:$I2_GROUP /usr/local/icinga/icinga2
1537 ```
1538
1539 #### Run
1540
1541 Start Icinga in foreground.
1542
1543 ```
1544 icinga2 daemon
1545 ```
1546
1547 Reloads triggered with HUP or cluster syncs just put the process into background.
1548
1549 #### Plugins
1550
1551 ```
1552 brew install monitoring-plugins
1553
1554 sudo vim /usr/local/icinga/icinga2/etc/icinga2/constants.conf
1555 const PluginDir = "/usr/local/sbin"
1556 ```
1557
1558 #### Backends: Redis
1559
1560 ```
1561 brew install redis
1562 brew services start redis
1563 ```
1564
1565 #### Databases: MariaDB
1566
1567 ```
1568 brew install mariadb
1569 mkdir -p /usr/local/etc/my.cnf.d
1570 brew services start mariadb
1571
1572 mysql_secure_installation
1573 ```
1574
1575 ```
1576 vim $HOME/.my.cnf
1577
1578 [client]
1579 user = root
1580 password = supersecurerootpassword
1581
1582 sudo -i
1583 ln -s /Users/michi/.my.cnf $HOME/.my.cnf
1584 exit
1585 ```
1586
1587 ```
1588 mysql -e 'create database icinga;'
1589 mysql -e "grant all on icinga.* to 'icinga'@'localhost' identified by 'icinga';"
1590 mysql icinga < $HOME/dev/icinga/icinga2/lib/db_ido_mysql/schema/mysql.sql
1591 ```
1592
1593 #### API
1594
1595 ```
1596 icinga2 api setup
1597 cd /usr/local/icinga/icinga2/var/lib/icinga2/certs
1598 HOST_NAME=mbpmif.int.netways.de
1599 icinga2 pki new-cert --cn ${HOST_NAME} --csr ${HOST_NAME}.csr --key ${HOST_NAME}.key
1600 icinga2 pki sign-csr --csr ${HOST_NAME}.csr --cert ${HOST_NAME}.crt
1601 echo "const NodeName = \"${HOST_NAME}\"" >> /usr/local/icinga/icinga2/etc/icinga2/constants.conf
1602 ```
1603
1604 #### Web
1605
1606 While it is recommended to use Docker or the Icinga Web 2 development VM pointing to the shared IDO database resource/REST API, you can also install it locally on macOS.
1607
1608 The required steps are described in [this script](https://github.com/dnsmichi/dotfiles/blob/master/icingaweb2.sh).
1609
1610 ### Windows Dev Environment <a id="development-windows-dev-env"></a>
1611
1612 The following sections explain how to setup the required build tools
1613 and how to run and debug the code.
1614
1615 #### Chocolatey
1616
1617 Open an administrative command prompt (Win key, type “cmd”, right-click and “run as administrator”) and paste the following instructions:
1618
1619 ```
1620 @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
1621 ```
1622
1623 #### Git, Posh and Vim
1624
1625 In case you are used to `vim`, start a new administrative Powershell:
1626
1627 ```
1628 choco install -y vim
1629 ```
1630
1631 The same applies for Git integration in Powershell:
1632
1633 ```
1634 choco install -y poshgit
1635 ```
1636
1637 ![Powershell Posh Git](images/development/windows_powershell_posh_git.png)
1638
1639 In order to fix the colors for commands like `git status` or `git diff`,
1640 edit `$HOME/.gitconfig` in your Powershell and add the following lines:
1641
1642 ```
1643 vim $HOME/.gitconfig
1644
1645 [color "status"]
1646     changed = cyan bold
1647     untracked = yellow bold
1648     added = green bold
1649     branch = cyan bold
1650     unmerged = red bold
1651
1652 [color "diff"]
1653     frag = cyan
1654     new = green bold
1655     commit = yellow
1656     old = red white
1657
1658 [color "branch"]
1659   current = yellow reverse
1660   local = yellow
1661   remote = green bold
1662   remote = red bold
1663 ```
1664
1665 #### Visual Studio
1666
1667 Thanks to Microsoft they’ll now provide their Professional Edition of Visual Studio 2017
1668 as community version, free for use for open source projects such as Icinga.
1669 The installation requires ~9GB disk space. [Download](https://www.visualstudio.com/downloads/)
1670 the web installer and start the installation.
1671
1672 You need a free Microsoft account to download and also store your preferences.
1673
1674 Install the following Workloads:
1675
1676 * C++ Desktop Development (icinga2.exe)
1677 * .NET Desktop Development (Agent Setup Wizard in C#)
1678
1679 In addition also choose these individual components on Visual Studio 2017:
1680
1681 * .NET
1682     * .NET Framework 4.6 targeting pack
1683     * .NET Framework 4.6.1 SDK
1684     * .NET Framework 4.6.1 targeting pack
1685 * Code tools
1686     * Git for Windows
1687     * Static analysis tools
1688     * GitHub Extension for Visual Studio
1689 * Compilers, build tools and runtimes
1690     * C# and Visual Basic Roslyn compilers
1691     * C++/CLI Support
1692     * VC++ 2017 v141 toolset (x86_64)
1693 * Debugging and testing
1694     * C++ profiling tools
1695     * Just-in-Time debugger
1696 * Development activities
1697     * Visual Studio C++ core features
1698 * Games and Graphics
1699     * Graphics debugger and GPU profiler for DirectX (required by C++ profiling tools)
1700 * SDKs, libraries and frameworks
1701     * Graphics Tools Windows 8.1 SDK (required by C++ profiling tools)
1702     * Windows 10 SDK **10.0.10240.0 - exactly this version**
1703     * Windows 8.1 SDK
1704     * Windows Universal C Runtime
1705
1706 After a while, Visual Studio will be ready.
1707
1708 ##### Style Guide for Visual Studio
1709
1710 Navigate into `Tools > Options > Text Editor` and repeat the following for
1711
1712 - C++
1713 - C#
1714
1715 Navigate into `Tabs` and set:
1716
1717 - Indenting: Smart (default)
1718 - Tab size: 4
1719 - Indent size: 4
1720 - Keep tabs (instead of spaces)
1721
1722 ![Visual Studio Tabs](images/development/windows_visual_studio_tabs_c++.png)
1723
1724
1725 #### Flex and Bison
1726
1727 Install it using [chocolatey](https://www.wireshark.org/docs/wsdg_html_chunked/ChSetupWin32.html):
1728
1729 ```
1730 choco install -y winflexbison
1731 ```
1732
1733 Chocolatey installs these tools into the hidden directory `C:\ProgramData\chocolatey\lib\winflexbison\tools`.
1734
1735 #### OpenSSL
1736
1737 Icinga 2 requires the OpenSSL library. [Download](http://slproweb.com/products/Win32OpenSSL.html)
1738 and install it into the default path.
1739
1740 Install both, 32 and 64 bit variants.
1741
1742 Once asked for `Copy OpenSSLs DLLs to` select `The Windows system directory`. That way CMake/Visual Studio
1743 will automatically detect them for builds and packaging.
1744
1745 > **Note**
1746 >
1747 > We cannot use the chocolatey package as this one does not provide any development headers.
1748 >
1749 > Choose 1.1.1 LTS from manual downloads for best compatibility.
1750
1751 #### Boost
1752
1753 Icinga needs the development header and library files from the Boost library.
1754
1755 ##### Pre-built Binaries
1756
1757 Prefer the pre-built package over self-compiling, if the newest version already exists.
1758
1759 Download the [boost-binaries](https://sourceforge.net/projects/boost/files/boost-binaries/) for
1760
1761 - msvc-14.1 is Visual Studio 2017
1762 - 64 for 64 bit builds
1763
1764 ```
1765 https://sourceforge.net/projects/boost/files/boost-binaries/1.71.0/boost_1_71_0-msvc-14.1-64.exe/download
1766 ```
1767
1768 Run the installer and leave the default installation path in `C:\local\boost_1_71_0`.
1769
1770
1771 ##### Source & Compile
1772
1773 In order to use the boost development header and library files you need to [download](http://www.boost.org/users/download/)
1774 Boost and then extract it to e.g. `C:\local\boost_1_71_0`.
1775
1776 > **Note**
1777 >
1778 > Just use `C:\local`, the zip file already contains the sub folder. Extraction takes a while,
1779 > the archive contains more than 70k files.
1780
1781 In order to integrate Boost into Visual Studio 2017, open the `Developer Command Prompt` from the start menu,
1782 and navigate to `C:\local\boost_1_71_0`.
1783
1784 Execute `bootstrap.bat` first.
1785
1786 ```
1787 cd C:\local\boost_1_71_0
1788 bootstrap.bat
1789 ```
1790
1791 Once finished, specify the required `toolset` to compile boost against Visual Studio.
1792 This takes quite some time in a Windows VM. Boost Context uses Assembler code,
1793 which isn't treated as exception safe by the VS compiler. Therefore set the
1794 additional compilation flag according to [this entry](https://lists.boost.org/Archives/boost/2015/08/224570.php).
1795
1796 ```
1797 b2 --toolset=msvc-14.1 asmflags=\safeseh
1798 ```
1799
1800 ![Windows Boost Build in VS2017 Development Console](images/development/windows_boost_build_dev_cmd.png)
1801
1802 #### TortoiseGit
1803
1804 TortoiseGit provides a graphical integration into the Windows explorer. This makes it easier to checkout, commit
1805 and whatnot.
1806
1807 [Download](https://tortoisegit.org/download/) TortoiseGit on your system.
1808
1809 In order to clone via Git SSH you also need to create a new directory called `.ssh`
1810 inside your user's home directory.
1811 Therefore open a command prompt (win key, type `cmd`, enter) and run `mkdir .ssh`.
1812 Add your `id_rsa` private key and `id_rsa.pub` public key files into that directory.
1813
1814 Start the setup routine and choose `OpenSSH` as default secure transport when asked.
1815
1816 Open a Windows Explorer window and navigate into
1817
1818 ```
1819 cd %HOMEPATH%\source\repos
1820 ```
1821
1822 Right click and select `Git Clone` from the context menu.
1823
1824 Use `ssh://git@github.com/icinga/icinga2.git` for SSH clones, `https://github.com/icinga/icinga2.git` otherwise.
1825
1826 #### Packages
1827
1828 CMake uses CPack and NSIS to create the setup executable including all binaries and libraries
1829 in addition to setup dialogues and configuration. Therefore we’ll need to install [NSIS](http://nsis.sourceforge.net/Download)
1830 first.
1831
1832 We also need to install the Windows Installer XML (WIX) toolset.
1833
1834 ```
1835 choco install -y wixtoolset
1836 ```
1837
1838 #### CMake
1839
1840 Icinga 2 uses CMake to manage the build environment. You can generate the Visual Studio project files
1841 using CMake. [Download](https://cmake.org/download/) and install CMake. Select to add it to PATH for all users
1842 when asked.
1843
1844 > **Note**
1845 >
1846 > In order to properly detect the Boost libraries, install the CMake 3.14+.
1847
1848 Once setup is completed, open a command prompt and navigate to
1849
1850 ```
1851 cd %HOMEPATH%\source\repos
1852 ```
1853
1854 Build Icinga with specific CMake variables. This generates a new Visual Studio project file called `icinga2.sln`.
1855
1856 You need to specify the previously installed component paths:
1857
1858 Variable              | Value                                                                | Description
1859 ----------------------|----------------------------------------------------------------------|-------------------------------------------------------
1860 `BOOST_ROOT`          | `C:\local\boost_1_71_0`                                                    | Root path where you've extracted and compiled Boost.
1861 `BOOST_LIBRARYDIR`    | Binary: `C:\local\boost_1_71_0\lib64-msvc-14.1`, Source: `C:\local\boost_1_71_0\stage` | Path to the static compiled Boost libraries, directory must contain `lib`.
1862 `BISON_EXECUTABLE`    | `C:\ProgramData\chocolatey\lib\winflexbison\tools\win_bison.exe`     | Path to the Bison executable.
1863 `FLEX_EXECUTABLE`     | `C:\ProgramData\chocolatey\lib\winflexbison\tools\win_flex.exe`      | Path to the Flex executable.
1864 `ICINGA2_WITH_MYSQL`  | OFF                                                                  | Requires extra setup for MySQL if set to `ON`. Not supported for client setups.
1865 `ICINGA2_WITH_PGSQL`  | OFF                                                                  | Requires extra setup for PgSQL if set to `ON`. Not supported for client setups.
1866 `ICINGA2_UNITY_BUILD` | OFF                                                                  | Disable unity builds for development environments.
1867
1868 Tip: If you have previously opened a terminal, run `refreshenv` to re-read updated PATH variables.
1869
1870 ##### Build Scripts
1871
1872 Icinga provides the build scripts inside the Git repository.
1873
1874 Open a new Powershell and navigate into the cloned Git repository. Set
1875 specific environment variables and run the build scripts.
1876
1877 ```
1878 cd %HOMEPATH%\source\repos
1879
1880 $env:ICINGA2_BUILDPATH='debug'
1881 $env:CMAKE_BUILD_TYPE='Debug'
1882 $env:OPENSSL_ROOT_DIR='C:\OpenSSL-Win64'
1883 $env:BOOST_ROOT='C:\local\boost_1_71_0'
1884 $env:BOOST_LIBRARYDIR='C:\local\boost_1_71_0\lib64-msvc-14.1'
1885
1886 .\tools\win32\configure.ps1
1887 .\tools\win32\build.ps1
1888 .\tools\win32\test.ps1
1889 ```
1890
1891 > **Note**
1892 >
1893 > You may need to modify `configure.ps1` and
1894 > add a changed CMake variable for the installation
1895 > prefix: `-DCMAKE_INSTALL_PREFIX="C:\Program Files\Icinga2-build"`.
1896
1897 #### Icinga 2 in Visual Studio
1898
1899 Navigate to
1900
1901 ```
1902 cd %HOMEPATH%\source\repos\icinga2
1903 ```
1904
1905 Open `icinga2.sln`. Log into Visual Studio when asked.
1906
1907 On the right panel, select to build the `Bin/icinga-app` solution.
1908
1909 The executable binaries are located in `Bin\Release\Debug` in your `icinga2`
1910 project directory.
1911
1912 Navigate there and run `icinga2.exe --version`.
1913
1914 ```
1915 cd %HOMEPATH%\source\repos\icinga2\Bin\Release\Debug
1916 icinga2.exe --version
1917 ```
1918
1919
1920 #### Release Package
1921
1922 This is part of the build process script already.
1923
1924 > **Note**
1925 >
1926 > You may need to modify `configure.ps1` and
1927 > add a changed CMake variable for the installation
1928 > prefix: `-DCMAKE_INSTALL_PREFIX="C:\Program Files\Icinga2-build"`.
1929
1930 ```
1931 cd %HOMEPATH%\source\repos
1932
1933 $env:ICINGA2_BUILDPATH='debug'
1934 $env:CMAKE_BUILD_TYPE='Debug'
1935 $env:OPENSSL_ROOT_DIR='C:\OpenSSL-Win64'
1936 $env:BOOST_ROOT='C:\local\boost_1_71_0'
1937 $env:BOOST_LIBRARYDIR='C:\local\boost_1_71_0\lib64-msvc-14.1'
1938
1939 .\tools\win32\configure.ps1
1940 .\tools\win32\build.ps1
1941 .\tools\win32\test.ps1
1942 ```
1943
1944
1945
1946 ### Embedded Dev Env: Pi <a id="development-embedded-dev-env"></a>
1947
1948 > **Note**
1949 >
1950 > This isn't officially supported yet, just a few hints how you can do it yourself.
1951
1952 The following examples source from armhf on Raspberry Pi.
1953
1954 #### ccache
1955
1956 ```
1957 apt install -y ccache
1958
1959 /usr/sbin/update-ccache-symlinks
1960
1961 echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a ~/.bashrc
1962
1963 source ~/.bashrc && echo $PATH
1964 ```
1965
1966 #### Build
1967
1968 Copy the icinga2 source code into `$HOME/icinga2`. Clone the `deb-icinga2` repository into `debian/`.
1969
1970 ```
1971 git clone https://github.com/Icinga/icinga2 $HOME/icinga2
1972 git clone https://github.com/Icinga/deb-icinga2 $HOME/icinga2/debian
1973 ```
1974
1975 Then build a Debian package and install it like normal.
1976 ```
1977 dpkg-buildpackage -uc -us
1978 ```
1979
1980 ## Package Builds <a id="development-package-builds"></a>
1981
1982 This documentation is explicitly meant for packagers and the Icinga
1983 build infrastructure.
1984
1985 The following requirements need to be fulfilled in order to build the
1986 Icinga application using a dist tarball (including notes for distributions):
1987
1988 * cmake >= 2.6
1989 * GNU make (make) or ninja-build
1990 * C++ compiler which supports C++11
1991     * RHEL/Fedora/SUSE: gcc-c++ >= 4.7 (extra Developer Tools on RHEL5/6 see below)
1992     * Debian/Ubuntu: build-essential
1993     * Alpine: build-base
1994     * you can also use clang++
1995 * pkg-config
1996 * OpenSSL library and header files >= 1.0.1
1997     * RHEL/Fedora: openssl-devel
1998     * SUSE: libopenssl-devel
1999     * Debian/Ubuntu: libssl-dev
2000     * Alpine: libressl-dev
2001 * Boost library and header files >= 1.66.0
2002     * RHEL/Fedora: boost166-devel
2003     * Debian/Ubuntu: libboost-all-dev
2004     * Alpine: boost-dev
2005 * GNU bison (bison)
2006 * GNU flex (flex) >= 2.5.35
2007 * systemd headers
2008     * Only required when using systemd
2009     * Debian/Ubuntu: libsystemd-dev
2010     * RHEL/Fedora: systemd-devel
2011
2012 ### Optional features <a id="development-package-builds-optional-features"></a>
2013
2014 * MySQL (disable with CMake variable `ICINGA2_WITH_MYSQL` to `OFF`)
2015     * RHEL/Fedora: mysql-devel
2016     * SUSE: libmysqlclient-devel
2017     * Debian/Ubuntu: default-libmysqlclient-dev | libmysqlclient-dev
2018     * Alpine: mariadb-dev
2019 * PostgreSQL (disable with CMake variable `ICINGA2_WITH_PGSQL` to `OFF`)
2020     * RHEL/Fedora: postgresql-devel
2021     * Debian/Ubuntu: libpq-dev
2022     * postgresql-dev on Alpine
2023 * libedit (CLI console)
2024     * RHEL/Fedora: libedit-devel on CentOS (RHEL requires rhel-7-server-optional-rpms)
2025     * Debian/Ubuntu/Alpine: libedit-dev
2026 * Termcap (only required if libedit doesn't already link against termcap/ncurses)
2027     * RHEL/Fedora: libtermcap-devel
2028     * Debian/Ubuntu: (not necessary)
2029
2030 ### Special requirements <a id="development-package-builds-special-requirements"></a>
2031
2032 **FreeBSD**: libexecinfo (automatically used when Icinga 2 is installed via port or package)
2033
2034 **RHEL6**: Requires a newer boost version which is available on packages.icinga.com
2035 with a version suffixed name.
2036
2037 ### Runtime user environment <a id="development-package-builds-runtime-user-env"></a>
2038
2039 By default Icinga will run as user `icinga` and group `icinga`. Additionally the
2040 external command pipe and livestatus features require a dedicated command group
2041 `icingacmd`. You can choose your own user/group names and pass them to CMake
2042 using the `ICINGA2_USER`, `ICINGA2_GROUP` and `ICINGA2_COMMAND_GROUP` variables.
2043
2044 ```
2045 # groupadd icinga
2046 # groupadd icingacmd
2047 # useradd -c "icinga" -s /sbin/nologin -G icingacmd -g icinga icinga
2048 ```
2049
2050 On Alpine (which uses ash busybox) you can run:
2051
2052 ```
2053 # addgroup -S icinga
2054 # addgroup -S icingacmd
2055 # adduser -S -D -H -h /var/spool/icinga2 -s /sbin/nologin -G icinga -g icinga icinga
2056 # adduser icinga icingacmd
2057 ```
2058
2059 Add the web server user to the icingacmd group in order to grant it write
2060 permissions to the external command pipe and livestatus socket:
2061
2062 ```
2063 # usermod -a -G icingacmd www-data
2064 ```
2065
2066 Make sure to replace "www-data" with the name of the user your web server
2067 is running as.
2068
2069 ### Building Icinga 2: Example <a id="development-package-builds-example"></a>
2070
2071 Once you have installed all the necessary build requirements you can build
2072 Icinga 2 using the following commands:
2073
2074 ```
2075 $ mkdir release && cd release
2076 $ cmake ..
2077 $ cd ..
2078 $ make -C release
2079 $ make install -C release
2080 ```
2081
2082 You can specify an alternative installation prefix using `-DCMAKE_INSTALL_PREFIX`:
2083
2084 ```
2085 $ cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/icinga2
2086 ```
2087
2088 ### CMake Variables <a id="development-package-builds-cmake-variables"></a>
2089
2090 In addition to `CMAKE_INSTALL_PREFIX` here are most of the supported Icinga-specific cmake variables.
2091
2092 For all variables regarding defaults paths on in CMake, see
2093 [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html).
2094
2095 Also see `CMakeLists.txt` for details.
2096
2097 #### System Environment
2098
2099 * `CMAKE_INSTALL_SYSCONFDIR`: The configuration directory; defaults to `CMAKE_INSTALL_PREFIX/etc`
2100 * `CMAKE_INSTALL_LOCALSTATEDIR`: The state directory; defaults to `CMAKE_INSTALL_PREFIX/var`
2101 * `ICINGA2_CONFIGDIR`: Main config directory; defaults to `CMAKE_INSTALL_SYSCONFDIR/icinga2` usually `/etc/icinga2`
2102 * `ICINGA2_CACHEDIR`: Directory for cache files; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/cache/icinga2` usually `/var/cache/icinga2`
2103 * `ICINGA2_DATADIR`: Data directory  for the daemon; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/lib/icinga2` usually `/var/lib/icinga2`
2104 * `ICINGA2_LOGDIR`: Logfiles of the daemon; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/log/icinga2 usually `/var/log/icinga2`
2105 * `ICINGA2_SPOOLDIR`: Spooling directory ; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/spool/icinga2` usually `/var/spool/icinga2`
2106 * `ICINGA2_INITRUNDIR`: Runtime data for the init system; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/run/icinga2` usually `/run/icinga2`
2107 * `ICINGA2_GIT_VERSION_INFO`: Whether to use Git to determine the version number; defaults to `ON`
2108 * `ICINGA2_USER`: The user Icinga 2 should run as; defaults to `icinga`
2109 * `ICINGA2_GROUP`: The group Icinga 2 should run as; defaults to `icinga`
2110 * `ICINGA2_COMMAND_GROUP`: The command group Icinga 2 should use; defaults to `icingacmd`
2111 * `ICINGA2_SYSCONFIGFILE`: Where to put the config file the initscript/systemd pulls it's dirs from;
2112 * defaults to `CMAKE_INSTALL_PREFIX/etc/sysconfig/icinga2`
2113 * `ICINGA2_PLUGINDIR`: The path for the Monitoring Plugins project binaries; defaults to `/usr/lib/nagios/plugins`
2114
2115 #### Build Optimization
2116
2117 * `ICINGA2_UNITY_BUILD`: Whether to perform a unity build; defaults to `ON`. Note: This requires additional memory and is not advised for building VMs, Docker for Mac and embedded hardware.
2118 * `ICINGA2_LTO_BUILD`: Whether to use link time optimization (LTO); defaults to `OFF`
2119
2120 #### Init System
2121
2122 * `USE_SYSTEMD=ON|OFF`: Use systemd or a classic SysV initscript; defaults to `OFF`
2123 * `INSTALL_SYSTEMD_SERVICE_AND_INITSCRIPT=ON|OFF` Force install both the systemd service definition file
2124   and the SysV initscript in parallel, regardless of how `USE_SYSTEMD` is set.
2125   Only use this for special packaging purposes and if you know what you are doing.
2126   Defaults to `OFF`.
2127
2128 #### Features
2129
2130 * `ICINGA2_WITH_CHECKER`: Determines whether the checker module is built; defaults to `ON`
2131 * `ICINGA2_WITH_COMPAT`: Determines whether the compat module is built; defaults to `ON`
2132 * `ICINGA2_WITH_LIVESTATUS`: Determines whether the Livestatus module is built; defaults to `ON`
2133 * `ICINGA2_WITH_NOTIFICATION`: Determines whether the notification module is built; defaults to `ON`
2134 * `ICINGA2_WITH_PERFDATA`: Determines whether the perfdata module is built; defaults to `ON`
2135 * `ICINGA2_WITH_TESTS`: Determines whether the unit tests are built; defaults to `ON`
2136
2137 #### MySQL or MariaDB
2138
2139 The following settings can be tuned for the MySQL / MariaDB IDO feature.
2140
2141 * `ICINGA2_WITH_MYSQL`: Determines whether the MySQL IDO module is built; defaults to `ON`
2142 * `MYSQL_CLIENT_LIBS`: Client implementation used (mysqlclient / mariadbclient); defaults searches for `mysqlclient` and `mariadbclient`
2143 * `MYSQL_INCLUDE_DIR`: Directory containing include files for the mysqlclient; default empty -
2144   checking multiple paths like `/usr/include/mysql`
2145
2146 See [FindMySQL.cmake](https://github.com/Icinga/icinga2/blob/master/third-party/cmake/FindMySQL.cmake)
2147 for implementation details.
2148
2149 #### PostgreSQL
2150
2151 The following settings can be tuned for the PostgreSQL IDO feature.
2152
2153 * `ICINGA2_WITH_PGSQL`: Determines whether the PostgreSQL IDO module is built; defaults to `ON`
2154 * `PostgreSQL_INCLUDE_DIR`: Top-level directory containing the PostgreSQL include directories
2155 * `PostgreSQL_LIBRARY`: File path to PostgreSQL library : libpq.so (or libpq.so.[ver] file)
2156
2157 See [FindPostgreSQL.cmake](https://github.com/Icinga/icinga2/blob/master/third-party/cmake/FindPostgreSQL.cmake)
2158 for implementation details.
2159
2160 #### Version detection
2161
2162 CMake determines the Icinga 2 version number using `git describe` if the
2163 source directory is contained in a Git repository. Otherwise the version number
2164 is extracted from the [VERSION](VERSION) file. This behavior can be
2165 overridden by creating a file called `icinga-version.h.force` in the source
2166 directory. Alternatively the `-DICINGA2_GIT_VERSION_INFO=OFF` option for CMake
2167 can be used to disable the usage of `git describe`.
2168
2169
2170 ### Building RPMs <a id="development-package-builds-rpms"></a>
2171
2172 #### Build Environment on RHEL, CentOS, Fedora, Amazon Linux
2173
2174 Setup your build environment:
2175
2176 ```
2177 yum -y install rpmdevtools
2178 ```
2179
2180 #### Build Environment on SuSE/SLES
2181
2182 SLES:
2183
2184 ```
2185 zypper addrepo http://download.opensuse.org/repositories/devel:tools/SLE_12_SP4/devel:tools.repo
2186 zypper refresh
2187 zypper install rpmdevtools spectool
2188 ```
2189
2190 OpenSuSE:
2191
2192 ```
2193 zypper addrepo http://download.opensuse.org/repositories/devel:tools/openSUSE_Leap_15.0/devel:tools.repo
2194 zypper refresh
2195 zypper install rpmdevtools spectool
2196 ```
2197
2198 #### Package Builds <a id="development-package-builds-rpms-package-builds"></a>
2199
2200 Prepare the rpmbuild directory tree:
2201
2202 ```
2203 cd $HOME
2204 rpmdev-setuptree
2205 ```
2206
2207 Snapshot builds:
2208
2209 ```
2210 curl https://raw.githubusercontent.com/Icinga/rpm-icinga2/master/icinga2.spec -o $HOME/rpmbuild/SPECS/icinga2.spec
2211 ```
2212
2213 > **Note**
2214 >
2215 > The above command builds snapshot packages. Change to the `release` branch
2216 > for release package builds.
2217
2218 Copy the tarball to `rpmbuild/SOURCES` e.g. by using the `spectool` binary
2219 provided with `rpmdevtools`:
2220
2221 ```
2222 cd $HOME/rpmbuild/SOURCES
2223 spectool -g ../SPECS/icinga2.spec
2224
2225 cd $HOME/rpmbuild
2226 ```
2227
2228 Install the build dependencies. Example for CentOS 7:
2229
2230 ```
2231 yum -y install libedit-devel ncurses-devel gcc-c++ libstdc++-devel openssl-devel \
2232 cmake flex bison boost-devel systemd mysql-devel postgresql-devel httpd \
2233 selinux-policy-devel checkpolicy selinux-policy selinux-policy-doc
2234 ```
2235
2236 Note: If you are using Amazon Linux, systemd is not required.
2237
2238 A shorter way is available using the `yum-builddep` command on RHEL based systems:
2239
2240 ```
2241 yum-builddep SPECS/icinga2.spec
2242 ```
2243
2244 Build the RPM:
2245
2246 ```
2247 rpmbuild -ba SPECS/icinga2.spec
2248 ```
2249
2250 #### Additional Hints <a id="development-package-builds-rpms-additional-hints"></a>
2251
2252 ##### SELinux policy module
2253
2254 The following packages are required to build the SELinux policy module:
2255
2256 * checkpolicy
2257 * selinux-policy (selinux-policy on CentOS 6, selinux-policy-devel on CentOS 7)
2258 * selinux-policy-doc
2259
2260 ##### RHEL/CentOS 6
2261
2262 The RedHat Developer Toolset is required for building Icinga 2 beforehand.
2263 This contains a modern version of flex and a C++ compiler which supports
2264 C++11 features.
2265 ```
2266 cat >/etc/yum.repos.d/devtools-2.repo <<REPO
2267 [testing-devtools-2-centos-\$releasever]
2268 name=testing 2 devtools for CentOS $releasever
2269 baseurl=https://people.centos.org/tru/devtools-2/\$releasever/\$basearch/RPMS
2270 gpgcheck=0
2271 REPO
2272 ```
2273
2274 Dependencies to devtools-2 are used in the RPM SPEC, so the correct tools
2275 should be used for building.
2276
2277 As an alternative, you can use newer Boost packages provided on
2278 [packages.icinga.com](https://packages.icinga.com/epel).
2279 ```
2280 cat >$HOME/.rpmmacros <<MACROS
2281 %build_icinga_org 1
2282 MACROS
2283 ```
2284
2285 ##### Amazon Linux
2286
2287 If you prefer to build packages offline, a suitable Vagrant box is located
2288 [here](https://atlas.hashicorp.com/mvbcoding/boxes/awslinux/).
2289
2290 ### Build Debian/Ubuntu packages <a id="development-package-builds-deb"></a>
2291
2292 Setup your build environment on Debian/Ubuntu, copy the 'debian' directory from
2293 the Debian packaging Git repository (https://github.com/Icinga/deb-icinga2)
2294 into your source tree and run the following command:
2295
2296 ```
2297 dpkg-buildpackage -uc -us
2298 ```
2299
2300 ### Build Alpine Linux packages <a id="development-package-builds-alpine"></a>
2301
2302 A simple way to setup a build environment is installing Alpine in a chroot.
2303 In this way, you can set up an Alpine build environment in a chroot under a
2304 different Linux distro.
2305 There is a script that simplifies these steps with just two commands, and
2306 can be found [here](https://github.com/alpinelinux/alpine-chroot-install).
2307
2308 Once the build environment is installed, you can setup the system to build
2309 the packages by following [this document](https://wiki.alpinelinux.org/wiki/Creating_an_Alpine_package).
2310
2311 ### Build Post Install Tasks <a id="development-package-builds-post-install-tasks"></a>
2312
2313 After building Icinga 2 yourself, your package build system should at least run the following post
2314 install requirements:
2315
2316 * enable the `checker`, `notification` and `mainlog` feature by default
2317 * run 'icinga2 api setup' in order to enable the `api` feature and generate TLS certificates for the node
2318
2319 ### Run Icinga 2 <a id="development-package-builds-run-icinga"></a>
2320
2321 Icinga 2 comes with a binary that takes care of loading all the relevant
2322 components (e.g. for check execution, notifications, etc.):
2323
2324 ```
2325 icinga2 daemon
2326
2327 [2016-12-08 16:44:24 +0100] information/cli: Icinga application loader (version: v2.5.4-231-gb10a6b7; debug)
2328 [2016-12-08 16:44:24 +0100] information/cli: Loading configuration file(s).
2329 [2016-12-08 16:44:25 +0100] information/ConfigItem: Committing config item(s).
2330 ...
2331 ```
2332
2333 #### Init Script <a id="development-package-builds-init-script"></a>
2334
2335 Icinga 2 can be started as a daemon using the provided init script:
2336
2337 ```
2338 /etc/init.d/icinga2
2339 Usage: /etc/init.d/icinga2 {start|stop|restart|reload|checkconfig|status}
2340 ```
2341
2342 #### Systemd <a id="development-package-builds-systemd"></a>
2343
2344 If your distribution uses systemd:
2345
2346 ```
2347 systemctl {start|stop|reload|status|enable|disable} icinga2
2348 ```
2349
2350 In case the distribution is running systemd >227, you'll also
2351 need to package and install the `etc/initsystem/icinga2.service.limits.conf`
2352 file into `/etc/systemd/system/icinga2.service.d`.
2353
2354 #### openrc <a id="development-package-builds-openrc"></a>
2355
2356 Or if your distribution uses openrc (like Alpine):
2357
2358 ```
2359 rc-service icinga2
2360 Usage: /etc/init.d/icinga2 {start|stop|restart|reload|checkconfig|status}
2361 ```
2362
2363 Note: the openrc's init.d is not shipped by default.
2364 A working init.d with openrc can be found here: (https://git.alpinelinux.org/cgit/aports/plain/community/icinga2/icinga2.initd). If you have customized some path, edit the file and adjust it according with your setup.
2365 Those few steps can be followed:
2366
2367 ```
2368 wget https://git.alpinelinux.org/cgit/aports/plain/community/icinga2/icinga2.initd
2369 mv icinga2.initd /etc/init.d/icinga2
2370 chmod +x /etc/init.d/icinga2
2371 ```
2372
2373 Icinga 2 reads a single configuration file which is used to specify all
2374 configuration settings (global settings, hosts, services, etc.). The
2375 configuration format is explained in detail in the [doc/](doc/) directory.
2376
2377 By default `make install` installs example configuration files in
2378 `/usr/local/etc/icinga2` unless you have specified a different prefix or
2379 sysconfdir.
2380
2381
2382 ### Windows Builds <a id="development-package-builds-windows"></a>
2383
2384 The Windows MSI packages are located at https://packages.icinga.com/windows/
2385
2386 #### Requirements <a id="development-package-builds-windows-requirements"></a>
2387
2388 * 32 or 64-bit system
2389 * Visual Studio >= 14.1 2017
2390 * CMake >= 2.6
2391 * OpenSSL >= 1.1.1
2392 * Flex and Bison
2393
2394 ##### Visual Studio
2395
2396 Download the community edition from [visualstudio.com](https://www.visualstudio.com/en/downloads/)
2397
2398 Workloads to install:
2399
2400 * C++ Desktop
2401 * .NET Desktop
2402
2403 ##### OpenSSL for Icinga
2404
2405 Download custom OpenSSL builds from [openssl-windows GitHub project](https://github.com/Icinga/openssl-windows/releases).
2406
2407 You need to install a binary dist version to 'C:\\Program Files\\OpenSSL'.
2408
2409 The Powershell script `.\tools\win32\download-openssl.ps1` can be used for automated downloads.
2410
2411 ##### Chocolatey
2412
2413 A simple package manager for Windows, please see [install instructions](https://chocolatey.org/install).
2414
2415 ##### Git
2416
2417 Use Chocolatey, see [package details](https://chocolatey.org/packages/git).
2418
2419 ```
2420 choco install git
2421 ```
2422
2423 ##### Flex / Bison
2424
2425 Use Chocolatey, see [package details](https://chocolatey.org/packages/winflexbison3).
2426
2427 ```
2428 choco install winflexbison3
2429 ```
2430
2431 ##### CMake
2432
2433 Use Chocolatey, see [package details](https://chocolatey.org/packages/cmake)
2434 or download from: [cmake.org](https://cmake.org/download/)
2435
2436 ```
2437 choco install cmake
2438 ```
2439
2440 ##### WIX
2441
2442 Use Chocolatey, see [package details](https://chocolatey.org/packages/wixtoolset).
2443
2444 ```
2445 choco install wixtoolset
2446 ```
2447
2448 ##### Boost
2449
2450 Download third party Windows binaries from: [boost.org](http://www.boost.org/users/download/)
2451
2452 For example: `https://dl.bintray.com/boostorg/release/1.65.1/binaries/boost_1_65_1-msvc-14.1-64.exe`
2453
2454 *Warning:*
2455 * Must match your Visual Studio version!
2456 * CMake might not support the latest Boost version (we used CMake 3.10 and Boost 1_65_1)
2457
2458 Run the installer exe.
2459
2460
2461 #### Build Icinga 2
2462
2463 Run with VC Native x64 Command Prompt:
2464
2465 ```
2466 powershell .\tools\win32\configure.ps1
2467 powershell .\tools\win32\build.ps1
2468 powershell .\tools\win32\test.ps1
2469 ```
2470
2471 See these scripts for details.
2472
2473 #### CI: AppVeyor
2474
2475 We are building [Icinga 2 with AppVeyor](https://ci.appveyor.com/project/icinga/icinga2) for testing and CI integration.
2476
2477 Please check `appveyor.yml` for instructions.
2478
2479
2480
2481 ## Advanced Development Tips <a id="development-advanced"></a>
2482
2483 ### GDB Pretty Printers <a id="development-advanced-gdb-pretty-printer"></a>
2484
2485 Install the `boost`, `python` and `icinga2` pretty printers. Absolute paths are required,
2486 so please make sure to update the installation paths accordingly (`pwd`).
2487
2488 ```
2489 $ mkdir -p ~/.gdb_printers && cd ~/.gdb_printers
2490 ```
2491
2492 Boost Pretty Printers compatible with Python 3:
2493
2494 ```
2495 $ git clone https://github.com/mateidavid/Boost-Pretty-Printer.git && cd Boost-Pretty-Printer
2496 $ git checkout python-3
2497 $ pwd
2498 /home/michi/.gdb_printers/Boost-Pretty-Printer
2499 ```
2500
2501 Python Pretty Printers:
2502
2503 ```
2504 $ cd ~/.gdb_printers
2505 $ svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
2506 ```
2507
2508 Icinga 2 Pretty Printers:
2509
2510 ```
2511 $ mkdir -p ~/.gdb_printers/icinga2 && cd ~/.gdb_printers/icinga2
2512 $ wget https://raw.githubusercontent.com/Icinga/icinga2/master/tools/debug/gdb/icingadbg.py
2513 ```
2514
2515 Now you'll need to modify/setup your `~/.gdbinit` configuration file.
2516 You can download the one from Icinga 2 and modify all paths.
2517
2518 Example on Fedora 22:
2519
2520 ```
2521 $ wget https://raw.githubusercontent.com/Icinga/icinga2/master/tools/debug/gdb/gdbinit -O ~/.gdbinit
2522 $ vim ~/.gdbinit
2523
2524 set print pretty on
2525
2526 python
2527 import sys
2528 sys.path.insert(0, '/home/michi/.gdb_printers/icinga2')
2529 from icingadbg import register_icinga_printers
2530 register_icinga_printers()
2531 end
2532
2533 python
2534 import sys
2535 sys.path.insert(0, '/home/michi/.gdb_printers/python')
2536 from libstdcxx.v6.printers import register_libstdcxx_printers
2537 try:
2538     register_libstdcxx_printers(None)
2539 except:
2540     pass
2541 end
2542
2543 python
2544 import sys
2545 sys.path.insert(0, '/home/michi/.gdb_printers/Boost-Pretty-Printer')
2546 import boost_print
2547 boost_print.register_printers()
2548 end
2549 ```
2550
2551 If you are getting the following error when running gdb, the `libstdcxx`
2552 printers are already preloaded in your environment and you can remove
2553 the duplicate import in your `~/.gdbinit` file.
2554
2555 ```
2556 RuntimeError: pretty-printer already registered: libstdc++-v6
2557 ```
2558