-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
113 lines (98 loc) · 3.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"flag"
"fmt"
"os"
"simpleOpsgenie/controllers"
"simpleOpsgenie/models"
)
func main() {
TotalIncidentsVar := flag.String("total", "", "Incidents Totals by Status (opened, resolved, closed)")
GetIncidentVar := flag.String("get", "", "Incident Information (TinyID)")
ListIncidentsIDVar := flag.String("list", "", "List Incidents ID by Status (opened, resolved, closed)")
CreateIncidentVar := flag.String("create", "", "Create an Incident (Name or Number)")
ResolveIncidentVar := flag.Bool("resolve", false, "Resolve an Incident (will prompt for wich one)")
CloseIncidentVar := flag.Bool("close", false, "Close an Incident (will prompt for wich one)")
DeleteIncidentVar := flag.Bool("delete", false, "Delete an Incident (will prompt for wich one)")
CheckPostmortemsVar := flag.String("postmortem", "", "List portmortems by status (closed, resolved)")
if len(os.Args) < 2 {
fmt.Println("# SimpleOpsgenie v1.0")
fmt.Println("# Dont known what to do, exiting.")
os.Exit(0)
}
flag.Parse()
fmt.Println("# SimpleOpsgenie v1.0")
fmt.Println("# Querying the API...")
if *TotalIncidentsVar != "" {
TotalIncidents(TotalIncidentsVar)
}
if *GetIncidentVar != "" {
GetIncident(GetIncidentVar)
}
if *ListIncidentsIDVar != "" {
ListIncidentsID(ListIncidentsIDVar)
}
if *CreateIncidentVar != "" {
CreateIncident(CreateIncidentVar)
}
if *ResolveIncidentVar {
ResolveIncident(ResolveIncidentVar)
}
if *CloseIncidentVar {
CloseIncident(CloseIncidentVar)
}
if *DeleteIncidentVar {
DeleteIncident(DeleteIncidentVar)
}
if *CheckPostmortemsVar != "" {
CheckPostmortems(CheckPostmortemsVar)
}
}
func CreateIncident(CreateIncidentVar *string) {
controllers.CreateIncident(CreateIncidentVar)
}
func GetIncident(GetIncidentVar *string) {
if *GetIncidentVar != "" {
controllers.GetOneIncident(*GetIncidentVar)
}
}
func TotalIncidents(TotalIncidentsVar *string) {
if *TotalIncidentsVar == "opened" {
controllers.TotalIncidentList("opened")
} else if *TotalIncidentsVar == "resolved" {
controllers.TotalIncidentList("resolved")
} else if *TotalIncidentsVar == "closed" {
controllers.TotalIncidentList("closed")
} else if *TotalIncidentsVar == "" {
os.Exit(0)
}
}
func CheckPostmortems(CheckPostmortemsVar *string) {
if *CheckPostmortemsVar == "resolved" {
controllers.CheckPostMortems("resolved")
} else if *CheckPostmortemsVar == "closed" {
controllers.CheckPostMortems("closed")
} else if *CheckPostmortemsVar == "" {
os.Exit(0)
}
}
func ListIncidentsID(ListIncidentsIDVar *string) {
if *ListIncidentsIDVar == "opened" {
controllers.GetIdFromAll("opened")
} else if *ListIncidentsIDVar == "resolved" {
controllers.GetIdFromAll("resolved")
} else if *ListIncidentsIDVar == "closed" {
controllers.GetIdFromAll("closed")
} else if *ListIncidentsIDVar == "" {
os.Exit(0)
}
}
func ResolveIncident(ResolveIncidentVar *bool) {
controllers.ResolveIncident(models.PayloadUnitMirror{})
}
func CloseIncident(CloseIncidentVar *bool) {
controllers.CloseIncident(models.PayloadUnitMirror{})
}
func DeleteIncident(DeleteIncidentVar *bool) {
controllers.DeleteIncident(models.PayloadUnitMirror{})
}