1 6456042b 2022-01-06 o package icinga provides a client to the Icinga2 HTTP API.
3 6456042b 2022-01-06 o [](http://godocs.io/olowe.co/icinga)
5 2ad5e459 2022-01-12 o Send patches, questions or a friendly "hello" to the mailing list: [~otl/icinga@lists.sr.ht](mailto:~otl/icinga@lists.sr.ht) 🙂
6 2ad5e459 2022-01-12 o Or, read [the archives][list].
10 7aa5b055 2022-01-13 o See the [package overview godoc][godocs] for getting started examples.
12 6456042b 2022-01-06 o [godocs]: https://godocs.io/olowe.co/icinga
16 26fb88e9 2022-01-12 o Some code is automatically generated. Ensure it's up-to-date before starting work:
20 2ad5e459 2022-01-12 o Make some changes, then run the tests:
24 2ad5e459 2022-01-12 o Please send any patches to the [mailing list](https://lists.sr.ht/~otl/icinga):
26 2ad5e459 2022-01-12 o git send-email --to="~otl/icinga@lists.sr.ht" HEAD^
28 7aa5b055 2022-01-13 o For those unfamiliar with this workflow, see [git-send-email.io][sendemail].
30 7aa5b055 2022-01-13 o [list]: https://lists.sr.ht/~otl/icinga
31 7aa5b055 2022-01-13 o [sendemail]: https://git-send-email.io
35 26fb88e9 2022-01-12 o Some tests dial an instance of Icinga2 running on the loopback address
36 26fb88e9 2022-01-12 o and the standard Icinga2 port 5665 ("127.0.0.1:5665"). If this fails,
37 26fb88e9 2022-01-12 o those tests are skipped. To run these tests, create the following API
40 26fb88e9 2022-01-12 o object ApiUser "root" {
41 26fb88e9 2022-01-12 o password = "icinga"
42 26fb88e9 2022-01-12 o permissions = [ "*" ]
45 26fb88e9 2022-01-12 o Getting data from 127.0.0.1:5665 to an Icinga server is left as an
46 26fb88e9 2022-01-12 o exercise to the reader!
48 26fb88e9 2022-01-12 o Personally, I run an Alpine Linux virtual machine using qemu. You
49 26fb88e9 2022-01-12 o could also use the [official Icinga2 container image][image].
51 26fb88e9 2022-01-12 o [image]: https://hub.docker.com/r/icinga/icinga2
53 26fb88e9 2022-01-12 o ### Code generation
55 26fb88e9 2022-01-12 o Source code for the basic lookup, create and delete operations of some
56 26fb88e9 2022-01-12 o Icinga2 object types, such as Host and Service, are generated
59 dd1562c0 2022-01-18 o To generate the code, ensure the following tools are available:
61 dd1562c0 2022-01-18 o * POSIX shell (/bin/sh)
65 26fb88e9 2022-01-12 o The shell script crud.sh writes Go source code by reading a template
66 26fb88e9 2022-01-12 o file and doing some text substitution. It loops through object types,
67 26fb88e9 2022-01-12 o piping the template file crud.skel into the awk script crud.awk for
70 26fb88e9 2022-01-12 o crud.sh writes code to the standard output by default:
74 26fb88e9 2022-01-12 o If the flag `-o` is set, code will be written to the file
75 26fb88e9 2022-01-12 o specified instead of to standard output:
77 26fb88e9 2022-01-12 o ./crud.sh -o crud.go
79 26fb88e9 2022-01-12 o Code generation is used because the functions are trivial and call the exact
80 26fb88e9 2022-01-12 o same underlying methods on Client anyway. The only thing that differs is the type.
81 26fb88e9 2022-01-12 o Perhaps when Go gets type parameters then this will go away?
83 6456042b 2022-01-06 o ## Why Another Package?
85 6456042b 2022-01-06 o The [icinga2 terraform provider][tf] uses the package [github.com/lrsmith/go-icinga2-api/iapi][lrsmith].
86 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].
87 6456042b 2022-01-06 o Other properties of `iapi` felt unusual to me:
89 6456042b 2022-01-06 o * The client to the API has the confusing name `server`.
90 6456042b 2022-01-06 o * Every HTTP request creates a new http.Client.
91 6456042b 2022-01-06 o * Types have superfluous names like `HostStruct` instead of just `Host`.
92 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.
93 6456042b 2022-01-06 o * Every error returned from a function has a new name, rather than reusing the idiomatic name `err`.
95 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`.
97 6456042b 2022-01-06 o But I'm not being paid ;)
99 6456042b 2022-01-06 o [effectivego]: https://go.dev/doc/effective_go
100 6456042b 2022-01-06 o [tf]: https://registry.terraform.io/providers/Icinga/icinga2/latest
101 6456042b 2022-01-06 o [lrsmith]: https://godocs.io/github.com/lrsmith/go-icinga2-api/iapi