-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
134 lines (117 loc) · 3.65 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"time"
"github.com/360EntSecGroup-Skylar/excelize"
"gopkg.in/yaml.v2"
)
var currentTime time.Time = time.Now()
var (
xf *excelize.File = excelize.NewFile() // Output Excel File
xsh0, xsr1, xsr2 int // Excel Styles for table headers and rows
ff string // Flag for input config file (YAML)
)
func init() {
debu = log.New(os.Stdout, "[D] ", log.Ldate|log.Ltime)
info = log.New(os.Stdout, "[I] ", log.Ldate|log.Ltime)
warn = log.New(os.Stdout, "[W] ", log.Ldate|log.Ltime)
erro = log.New(os.Stdout, "[E] ", log.Ldate|log.Ltime)
var printVersion bool
flag.BoolVar(&printVersion, "v", false, "Prints version")
flag.StringVar(&ff, "f", "ocinfo.yaml", "Sets YAML file to configure OCinfo")
flag.Parse()
if printVersion {
info.Printf("OCinfo Version: %s", version)
info.Printf("Github Repo : https://github.com/orcunuso/ocinfo")
os.Exit(0)
}
configBytes, err := ioutil.ReadFile(ff)
perror(err, true)
err = yaml.Unmarshal(configBytes, &cfg)
perror(err, true)
err = validateConfig()
if err != nil {
os.Exit(101)
}
xsh0, _ = xf.NewStyle(`{
"font": {"family": "Consolas", "size": 8, "color": "#FFFFFF", "bold": true},
"border": [
{"type": "left", "color": "000000", "style": 1},
{"type": "right", "color": "000000", "style": 1},
{"type": "top", "color": "000000", "style": 1},
{"type": "bottom", "color": "000000", "style": 1}],
"fill": {"type": "pattern","color": ["#000000"],"pattern": 1}}`)
xsr1, _ = xf.NewStyle(`{
"font": {"family": "Consolas", "size": 8, "color": "#000000", "bold": false},
"border": [
{"type": "left", "color": "000000", "style": 1},
{"type": "right", "color": "000000", "style": 1},
{"type": "top", "color": "000000", "style": 1},
{"type": "bottom", "color": "000000", "style": 1}],
"fill": {"type": "pattern","color": ["#DCDCDC"],"pattern": 1}}`)
xsr2, _ = xf.NewStyle(`{
"font": {"family": "Consolas", "size": 8, "color": "#000000", "bold": false},
"border": [
{"type": "left", "color": "000000", "style": 1},
{"type": "right", "color": "000000", "style": 1},
{"type": "top", "color": "000000", "style": 1},
{"type": "bottom", "color": "000000", "style": 1}],
"fill": {"type": "pattern","color": ["#FFFFFF"],"pattern": 1}}`)
xf.SetSheetName("Sheet1", "Summary")
}
func main() {
info.Println("====================== Gathering data from clusters ========================")
// Create excel sheets seperated for each resource types
createClusterSheet()
if cfg.Sheets.Alerts {
createAlertSheet()
}
if cfg.Sheets.Nodes {
createNodeSheet()
}
if cfg.Sheets.Machines {
createMachineSheet()
}
if cfg.Sheets.Namespaces {
createNamespaceSheet()
}
if cfg.Sheets.Nsquotas {
createQuotaSheet()
}
if cfg.Sheets.Pvolumes {
createPVolumeSheet()
}
if cfg.Sheets.Daemonsets {
createDaemonsetSheet()
}
if cfg.Sheets.Routes {
createRouteSheet()
}
if cfg.Sheets.Services {
createServiceSheet()
}
if cfg.Sheets.Deployments {
createDeploymentSheet()
}
if cfg.Sheets.Pods {
createPodSheet()
}
createSummarySheet()
xf.SetActiveSheet(xf.GetSheetIndex("Summary"))
// Save excel file and upload to S3 bucket
info.Println("============================== Exporting data ==============================")
fileName := "ocinfo_" + currentTime.Format("20060102") + ".xlsx"
err := xf.SaveAs(fileName)
if err != nil {
erro.Println("Report cannot be created. Reason: ", err)
os.Exit(1)
}
info.Println("Report exported as", fileName)
if cfg.Output.S3.Provider != "" {
uploadFileS3(fileName)
}
info.Println("OCinfo successfully terminated")
}