1 6456042b 2022-01-06 o package icinga provides a client to the Icinga2 HTTP API.
3 87154adc 2022-02-04 o [](https://builds.sr.ht/~otl/icinga?)
5 6456042b 2022-01-06 o [](http://godocs.io/olowe.co/icinga)
7 fb8a219e 2022-10-22 o Send patches, questions or a friendly "hello" to the mailing list: [~otl/public-inbox@lists.sr.ht](mailto:~otl/public-inbox@lists.sr.ht)
8 2ad5e459 2022-01-12 o Or, read [the archives][list].
12 7aa5b055 2022-01-13 o See the [package overview godoc][godocs] for getting started examples.
14 6456042b 2022-01-06 o [godocs]: https://godocs.io/olowe.co/icinga
18 26fb88e9 2022-01-12 o Some code is automatically generated. Ensure it's up-to-date before starting work:
22 2ad5e459 2022-01-12 o Make some changes, then run the tests:
26 fb8a219e 2022-10-22 o Please send any patches to the [mailing list][list]:
28 fb8a219e 2022-10-22 o git send-email --to="~otl/public-inbox@lists.sr.ht" HEAD^
30 7aa5b055 2022-01-13 o For those unfamiliar with this workflow, see [git-send-email.io][sendemail].
32 fb8a219e 2022-10-22 o [list]: https://lists.sr.ht/~otl/public-inbox
33 7aa5b055 2022-01-13 o [sendemail]: https://git-send-email.io
37 b717ce9b 2022-02-04 o Some tests use a fake, in-process Icinga server. Not all features of
38 b717ce9b 2022-02-04 o the API are implemented, but on any unsupported request it should
39 b717ce9b 2022-02-04 o report an error. The fake server uses an in-memory map to store
40 b717ce9b 2022-02-04 o Icinga2 objects, which maps object's path in the API request (e.g.
41 b717ce9b 2022-02-04 o "objects/hosts/text.example.com") to the object's attributes (e.g.
42 b717ce9b 2022-02-04 o `check_command` and `display_name`).
44 26fb88e9 2022-01-12 o Some tests dial an instance of Icinga2 running on the loopback address
45 b717ce9b 2022-02-04 o and the standard Icinga2 port 5665 (`::1:5665`). If this fails, those
46 b717ce9b 2022-02-04 o tests are skipped. To run these tests, create the following API user:
48 b717ce9b 2022-02-04 o object ApiUser "icinga" {
49 b717ce9b 2022-02-04 o password = name
50 26fb88e9 2022-01-12 o permissions = [ "*" ]
53 b717ce9b 2022-02-04 o Getting data from the loopback interface to an Icinga server is left
54 b717ce9b 2022-02-04 o as an exercise to the reader!
56 26fb88e9 2022-01-12 o Personally, I run an Alpine Linux virtual machine using qemu. You
57 26fb88e9 2022-01-12 o could also use the [official Icinga2 container image][image].
59 26fb88e9 2022-01-12 o [image]: https://hub.docker.com/r/icinga/icinga2
61 26fb88e9 2022-01-12 o ### Code generation
63 26fb88e9 2022-01-12 o Source code for the basic lookup, create and delete operations of some
64 26fb88e9 2022-01-12 o Icinga2 object types, such as Host and Service, are generated
67 dd1562c0 2022-01-18 o To generate the code, ensure the following tools are available:
69 dd1562c0 2022-01-18 o * POSIX shell (/bin/sh)
73 26fb88e9 2022-01-12 o The shell script crud.sh writes Go source code by reading a template
74 26fb88e9 2022-01-12 o file and doing some text substitution. It loops through object types,
75 26fb88e9 2022-01-12 o piping the template file crud.skel into the awk script crud.awk for
78 26fb88e9 2022-01-12 o crud.sh writes code to the standard output by default:
82 26fb88e9 2022-01-12 o If the flag `-o` is set, code will be written to the file
83 26fb88e9 2022-01-12 o specified instead of to standard output:
85 26fb88e9 2022-01-12 o ./crud.sh -o crud.go
87 26fb88e9 2022-01-12 o Code generation is used because the functions are trivial and call the exact
88 26fb88e9 2022-01-12 o same underlying methods on Client anyway. The only thing that differs is the type.
89 26fb88e9 2022-01-12 o Perhaps when Go gets type parameters then this will go away?
91 6456042b 2022-01-06 o ## Why Another Package?
93 6456042b 2022-01-06 o The [icinga2 terraform provider][tf] uses the package [github.com/lrsmith/go-icinga2-api/iapi][lrsmith].
94 6456042b 2022-01-06 o As I read the source code I felt I wasn't reading idiomatic Go as detailed in documents like [Effective Go][effectivego].
95 6456042b 2022-01-06 o Other properties of `iapi` felt unusual to me:
97 6456042b 2022-01-06 o * The client to the API has the confusing name `server`.
98 6456042b 2022-01-06 o * Every HTTP request creates a new http.Client.
99 6456042b 2022-01-06 o * Types have superfluous names like `HostStruct` instead of just `Host`.
100 6456042b 2022-01-06 o * Every response body from the API is decoded from JSON into one data strucutre, marshalled into JSON again, then unmarshalled back into another.
101 6456042b 2022-01-06 o * Every error returned from a function has a new name, rather than reusing the idiomatic name `err`.
103 6456042b 2022-01-06 o If I was being paid, I'd create a fork and contribute patches upstream to carefully avoid breaking functionality of existing users of `iapi`.
105 6456042b 2022-01-06 o But I'm not being paid ;)
107 6456042b 2022-01-06 o [effectivego]: https://go.dev/doc/effective_go
108 6456042b 2022-01-06 o [tf]: https://registry.terraform.io/providers/Icinga/icinga2/latest
109 6456042b 2022-01-06 o [lrsmith]: https://godocs.io/github.com/lrsmith/go-icinga2-api/iapi