// Copyright Jan Dittberner // SPDX-License-Identifier: GPL-3.0-or-later // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // The main package for matrix-service-notification package main import ( "flag" "log" "os" "git.ditberner.info/jan/icinga2-matrix-notification/internal/icinga2" "git.ditberner.info/jan/icinga2-matrix-notification/internal/matrix" ) func main() { parameters := parseFlags() message, err := icinga2.BuildServiceNotification(parameters) if err != nil { log.Fatalf("could not build message: %v", err) } if err := matrix.SendMessage( parameters.MatrixServer.URL, parameters.MatrixRoom, parameters.MatrixToken, message, ); err != nil { log.Fatalf("could not send message: %v", err) } } func parseFlags() *icinga2.ServiceParameters { parameters := &icinga2.ServiceParameters{} flag.StringVar(¶meters.LongDateTime, "d", "", "long date time ($icinga.long_date_time$)") flag.StringVar(¶meters.Hostname, "l", "", "hostname ($host.name$)") flag.StringVar(¶meters.HostDisplayName, "n", "", "host display name ($host.display_name$)") flag.Var(¶meters.NotificationType, "t", "notification type ($notification_type$)") flag.StringVar(¶meters.ServiceName, "e", "", "service name ($service.name$)") flag.StringVar(¶meters.ServiceDisplayName, "u", "", "service display name ($service.display_name$)") flag.StringVar(¶meters.ServiceOutput, "o", "", "service output ($service.output$)") flag.Var(¶meters.ServiceState, "s", "service state ($service.state$)") flag.StringVar(¶meters.MatrixRoom, "m", "", "matrix room ($notification_matrix_room$)") flag.Var(¶meters.MatrixServer, "x", "matrix server ($notification_matrix_server$)") flag.StringVar(¶meters.MatrixToken, "y", "", "matrix access token ($notification_matrix_token$)") flag.StringVar(¶meters.HostAddress, "4", "", "host address ($address$)") flag.StringVar(¶meters.HostAddress6, "6", "", "host address ($address6$)") flag.StringVar(¶meters.NotificationAuthorName, "b", "", "notification author name ($notification.author_name$)") flag.StringVar(¶meters.NotificationComment, "c", "", "notification comment ($notification.comment$)") flag.Var(¶meters.IcingaWeb2URL, "i", "IcingaWeb 2 URL ($notification_icingaweb2url$)") flag.Parse() if err := parameters.ValidateRequired(); err != nil { flag.Usage() os.Exit(2) //nolint:mnd } return parameters }