Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/go-neb: init #89327

Merged
merged 2 commits into from Jun 16, 2020
Merged

nixos/go-neb: init #89327

merged 2 commits into from Jun 16, 2020

Conversation

mweinelt
Copy link
Member

@mweinelt mweinelt commented Jun 1, 2020

Motivation for this change

Go-neb is a matrix bot that was packaged in #87854. Now we deliver a simple module to easily set this up.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@tilpner @maralorn

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and simple module 👍

Even more bonus points if it comes with a NixOS test ✨

nixos/modules/services/networking/go-neb.nix Outdated Show resolved Hide resolved
nixos/modules/services/networking/go-neb.nix Show resolved Hide resolved
@maralorn
Copy link
Member

maralorn commented Jun 1, 2020

I have copied this module to my server and have alertmanager warnings (and a wikipedia bot) up and running with this.

{
  services.go-neb = {
    enable = true;
    baseUrl = "http://localhost";
    config = {
      clients = [{
        UserId = "@marabot:maralorn.de";
        AccessToken = config.m-0.private.matrix_marabot_token;
        HomeServerUrl = "https://matrix.maralorn.de";
        Sync = true;
        AutoJoinRooms = true;
        DisplayName = "marabot";
      }];
      realms = [ ];
      sessions = [ ];
      services = [
        {
          ID = "alertmanager_service";
          Type = "alertmanager";
          UserId = "@marabot:maralorn.de";
          Config = {
            webhook_url =
              "http://localhost:4050/services/hooks/YWxlcnRtYW5hZ2VyX3NlcnZpY2UK";
            rooms = {
              "!negVsngnYOmXYCLKiO:maralorn.de" = {
                text_template = ''
                  {{range .Alerts -}} [{{ .Status }}] {{index .Labels "alertname" }}: {{index .Annotations "description"}} {{ end -}}'';
                  html_template = ''
                    {{range .Alerts -}}
                      {{ $severity := index .Labels "severity" }}
                      {{ if eq .Status "firing" }}
                        {{ if eq $severity "critical"}}
                          <font color='red'><b>[FIRING - CRITICAL]</b></font>
                        {{ else if eq $severity "warning"}}
                          <font color='orange'><b>[FIRING - WARNING]</b></font>
                        {{ else }}
                          <b>[FIRING - {{ $severity }}]</b>
                        {{ end }}
                      {{ else }}
                        <font color='green'><b>[RESOLVED]</b></font>
                      {{ end }}
                      {{ index .Labels "alertname"}}:{{ index .Annotations "description"}}
                      <a href="{{ .GeneratorURL }}">source</a><br/>
                    {{end -}}
                    '';
                msg_type = "m.text"; # Must be either `m.text` or `m.notice`
              };
            };
          };
        }
        {
          ID = "wikipedia_service";
          Type = "wikipedia";
          UserID = "@marabot:maralorn.de"; # requires a Syncing client
          Config = { };
        }
      ];
    };
  };
}

@mweinelt
Copy link
Member Author

mweinelt commented Jun 2, 2020

Simple test added.

@mweinelt mweinelt force-pushed the go-neb-module branch 2 times, most recently from d4dfe1f to 6724f8f Compare June 2, 2020 00:22
@tilpner
Copy link
Member

tilpner commented Jun 2, 2020

In https://github.com/matrix-org/go-neb#quick-start, DATABASE_{TYPE,URL} are set, which is not replicated here. Where does this module store its state?

@maralorn
Copy link
Member

maralorn commented Jun 2, 2020

@tilpner the bot has two modes. Statefully saving the config in an sqlite DB or reading the config from a config file. So the DB you are mentioning is not data state but only for config state. We opted to support only the second option, because it supports the same features and is much more nix like.

@mweinelt
Copy link
Member Author

mweinelt commented Jun 2, 2020

@tilpner the bot has two modes. Statefully saving the config in an sqlite DB or reading the config from a config file. So the DB you are mentioning is not data state but only for config state. We opted to support only the second option, because it supports the same features and is much more nix like.

The partial source for this statement is here: https://github.com/matrix-org/go-neb/blob/81842c69f831b7dccaa685ccacbbe218d059d76c/config.sample.yaml#L5-L9

@tilpner
Copy link
Member

tilpner commented Jun 3, 2020

I see. It surprised me that they were exclusive modes, I was hoping it would operate in a hybrid mode, as e.g. reliable RSS feed consumption requires state.

Supporting only the declarative mode in this module is reasonable though. Thanks for writing it! :)

@maralorn
Copy link
Member

maralorn commented Jun 3, 2020

@aanderse Are you also satisfied with the state of this?

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a winner in my books. Thanks for the extra work on this one. Bonus points for all! ✨

I'm not a subject matter expert so I wouldn't think to merge this... but if you're just waiting for a merge and everyone agrees I'm certainly happy to do so based on that 👍

@aanderse
Copy link
Member

aanderse commented Jun 3, 2020

... and just as I say that I notice the test isn't added to the list of tests. Please add and we're good.

Simple test to start the unit with a dummy client and a dummy service
and check if it can receive webhooks.
@mweinelt
Copy link
Member Author

mweinelt commented Jun 3, 2020

@maralorn
Copy link
Member

@aanderse Can you maybe point us to a subject matter expert? Otherwise I'd opt for the merge.

@aanderse
Copy link
Member

@maralorn maybe @Ma27 knows a thing or two... but this looks really good, so I'll merge by end of day if no one has any objections.

Thanks! 🎉

@aanderse
Copy link
Member

@GrahamcOfBorg test go-neb

@aanderse aanderse merged commit b6108e0 into NixOS:master Jun 16, 2020
@aanderse
Copy link
Member

Oops! Thanks team ❤️

@mweinelt mweinelt deleted the go-neb-module branch June 16, 2020 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants