Skip to content

Commit debce92

Browse files
authored
Merge pull request #20 from amreo/master
Fixes #19
2 parents a0c5915 + 3335495 commit debce92

30 files changed

+97
-2894
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ module github.com/ercole-io/ercole-agent
33
go 1.12
44

55
require (
6-
github.com/PuerkitoBio/goquery v1.5.0
76
github.com/kardianos/service v1.0.0
87
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP7EJk=
2-
github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
31
github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o=
42
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
53
github.com/kardianos/service v1.0.0 h1:HgQS3mFfOlyntWX8Oke98JcJLqt1DBcHR4kxShpYef0=

marshal/database.go

Lines changed: 31 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -16,104 +16,46 @@
1616
package marshal
1717

1818
import (
19-
"log"
19+
"bufio"
2020
"strings"
2121

22-
"github.com/PuerkitoBio/goquery"
2322
"github.com/ercole-io/ercole-agent/model"
2423
)
2524

2625
// Database returns information about database extracted
2726
// from the db fetcher command output.
2827
func Database(cmdOutput []byte) model.Database {
29-
30-
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(cmdOutput)))
31-
32-
if err != nil {
33-
log.Fatal(err)
34-
}
35-
3628
var db model.Database
37-
38-
doc.Find("tr").Each(func(r int, row *goquery.Selection) { // there should be only one
39-
40-
sel := row.Find("td")
41-
42-
for i := range sel.Nodes {
43-
single := sel.Eq(i)
44-
value := cleanTr(single.Text())
45-
if i == 0 {
46-
db.Name = value
47-
}
48-
if i == 1 {
49-
db.UniqueName = value
50-
}
51-
if i == 2 {
52-
db.InstanceNumber = value
53-
}
54-
if i == 3 {
55-
db.Status = value
56-
}
57-
if i == 4 {
58-
db.Version = value
59-
}
60-
if i == 5 {
61-
db.Platform = value
62-
}
63-
if i == 6 {
64-
db.Archivelog = value
65-
}
66-
if i == 7 {
67-
db.Charset = value
68-
}
69-
if i == 8 {
70-
db.NCharset = value
71-
}
72-
if i == 9 {
73-
db.BlockSize = value
74-
}
75-
if i == 10 {
76-
db.CPUCount = value
77-
}
78-
if i == 11 {
79-
db.SGATarget = value
80-
}
81-
if i == 12 {
82-
db.PGATarget = value
83-
}
84-
if i == 13 {
85-
db.MemoryTarget = value
86-
}
87-
if i == 14 {
88-
db.SGAMaxSize = value
89-
}
90-
if i == 15 {
91-
db.SegmentsSize = value
92-
}
93-
if i == 16 {
94-
db.Used = value
95-
}
96-
if i == 17 {
97-
db.Allocated = value
98-
}
99-
if i == 18 {
100-
db.Elapsed = value
101-
}
102-
if i == 19 {
103-
db.DBTime = value
104-
}
105-
if i == 20 {
106-
db.Work = value
107-
}
108-
if i == 21 {
109-
db.ASM = parseBool(value)
110-
}
111-
if i == 22 {
112-
db.Dataguard = parseBool(value)
113-
}
29+
scanner := bufio.NewScanner(strings.NewReader(string(cmdOutput)))
30+
31+
for scanner.Scan() {
32+
line := scanner.Text()
33+
splitted := strings.Split(line, "|||")
34+
if len(splitted) == 23 {
35+
db.Name = strings.TrimSpace(splitted[0])
36+
db.UniqueName = strings.TrimSpace(splitted[1])
37+
db.InstanceNumber = strings.TrimSpace(splitted[2])
38+
db.Status = strings.TrimSpace(splitted[3])
39+
db.Version = strings.TrimSpace(splitted[4])
40+
db.Platform = strings.TrimSpace(splitted[5])
41+
db.Archivelog = strings.TrimSpace(splitted[6])
42+
db.Charset = strings.TrimSpace(splitted[7])
43+
db.NCharset = strings.TrimSpace(splitted[8])
44+
db.BlockSize = strings.TrimSpace(splitted[9])
45+
db.CPUCount = strings.TrimSpace(splitted[10])
46+
db.SGATarget = strings.TrimSpace(splitted[11])
47+
db.PGATarget = strings.TrimSpace(splitted[12])
48+
db.MemoryTarget = strings.TrimSpace(splitted[13])
49+
db.SGAMaxSize = strings.TrimSpace(splitted[14])
50+
db.SegmentsSize = strings.TrimSpace(splitted[15])
51+
db.Used = strings.TrimSpace(splitted[16])
52+
db.Allocated = strings.TrimSpace(splitted[17])
53+
db.Elapsed = strings.TrimSpace(splitted[18])
54+
db.DBTime = strings.TrimSpace(splitted[19])
55+
db.Work = strings.TrimSpace(splitted[20])
56+
db.ASM = parseBool(strings.TrimSpace(splitted[21]))
57+
db.Dataguard = parseBool(strings.TrimSpace(splitted[22]))
11458
}
115-
116-
})
117-
59+
}
11860
return db
11961
}

marshal/patches.go

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,32 @@
1616
package marshal
1717

1818
import (
19-
"log"
19+
"bufio"
2020
"strings"
2121

22-
"github.com/PuerkitoBio/goquery"
2322
"github.com/ercole-io/ercole-agent/model"
2423
)
2524

2625
// Patches returns information about database tablespaces extracted
2726
// from the tablespaces fetcher command output.
2827
func Patches(cmdOutput []byte) []model.Patch {
29-
30-
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(cmdOutput)))
31-
32-
if err != nil {
33-
log.Fatal(err)
34-
}
35-
3628
patches := []model.Patch{}
37-
38-
doc.Find("tr").Each(func(r int, row *goquery.Selection) {
39-
40-
var p model.Patch
41-
42-
sel := row.Find("td")
43-
44-
for i := range sel.Nodes {
45-
single := sel.Eq(i)
46-
value := cleanTr(single.Text())
47-
if i == 3 {
48-
p.Database = value
49-
}
50-
if i == 4 {
51-
p.Version = value
52-
}
53-
if i == 5 {
54-
p.PatchID = value
55-
}
56-
if i == 6 {
57-
p.Action = value
58-
}
59-
if i == 7 {
60-
p.Description = value
61-
}
62-
if i == 8 {
63-
p.Date = value
64-
}
29+
scanner := bufio.NewScanner(strings.NewReader(string(cmdOutput)))
30+
31+
for scanner.Scan() {
32+
patch := new(model.Patch)
33+
line := scanner.Text()
34+
splitted := strings.Split(line, "|||")
35+
if len(splitted) == 9 {
36+
patch.Database = strings.TrimSpace(splitted[3])
37+
patch.Version = strings.TrimSpace(splitted[4])
38+
patch.PatchID = strings.TrimSpace(splitted[5])
39+
patch.Action = strings.TrimSpace(splitted[6])
40+
patch.Description = strings.TrimSpace(splitted[7])
41+
patch.Date = strings.TrimSpace(splitted[8])
42+
43+
patches = append(patches, *patch)
6544
}
66-
67-
patches = append(patches, p)
68-
69-
})
70-
45+
}
7146
return patches
7247
}

marshal/schemas.go

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,32 @@
1616
package marshal
1717

1818
import (
19-
"log"
19+
"bufio"
2020
"strings"
2121

22-
"github.com/PuerkitoBio/goquery"
2322
"github.com/ercole-io/ercole-agent/model"
2423
)
2524

2625
// Schemas returns information about database tablespaces extracted
2726
// from the tablespaces fetcher command output.
2827
func Schemas(cmdOutput []byte) []model.Schema {
29-
30-
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(cmdOutput)))
31-
32-
if err != nil {
33-
log.Fatal(err)
34-
}
35-
36-
var scs []model.Schema
37-
38-
doc.Find("tr").Each(func(r int, row *goquery.Selection) {
39-
40-
var sc model.Schema
41-
42-
sel := row.Find("td")
43-
44-
for i := range sel.Nodes {
45-
single := sel.Eq(i)
46-
value := cleanTr(single.Text())
47-
if i == 2 {
48-
sc.Database = value
49-
}
50-
if i == 3 {
51-
sc.User = value
52-
}
53-
if i == 4 {
54-
sc.Total = parseInt(value)
55-
}
56-
if i == 5 {
57-
sc.Tables = parseInt(value)
58-
}
59-
if i == 6 {
60-
sc.Indexes = parseInt(value)
61-
}
62-
if i == 7 {
63-
sc.LOB = parseInt(value)
64-
}
28+
schemas := []model.Schema{}
29+
scanner := bufio.NewScanner(strings.NewReader(string(cmdOutput)))
30+
31+
for scanner.Scan() {
32+
schema := new(model.Schema)
33+
line := scanner.Text()
34+
splitted := strings.Split(line, "|||")
35+
if len(splitted) == 8 {
36+
schema.Database = strings.TrimSpace(splitted[2])
37+
schema.User = strings.TrimSpace(splitted[3])
38+
schema.Total = parseInt(strings.TrimSpace(splitted[4]))
39+
schema.Tables = parseInt(strings.TrimSpace(splitted[5]))
40+
schema.Indexes = parseInt(strings.TrimSpace(splitted[6]))
41+
schema.LOB = parseInt(strings.TrimSpace(splitted[7]))
42+
43+
schemas = append(schemas, *schema)
6544
}
66-
67-
scs = append(scs, sc)
68-
69-
})
70-
71-
return scs
45+
}
46+
return schemas
7247
}

marshal/tablespaces.go

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,33 @@
1616
package marshal
1717

1818
import (
19-
"log"
19+
"bufio"
2020
"strings"
2121

22-
"github.com/PuerkitoBio/goquery"
2322
"github.com/ercole-io/ercole-agent/model"
2423
)
2524

2625
// Tablespaces returns information about database tablespaces extracted
2726
// from the tablespaces fetcher command output.
2827
func Tablespaces(cmdOutput []byte) []model.Tablespace {
29-
30-
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(cmdOutput)))
31-
32-
if err != nil {
33-
log.Fatal(err)
34-
}
35-
36-
var tbs []model.Tablespace
37-
38-
doc.Find("tr").Each(func(r int, row *goquery.Selection) {
39-
40-
var ts model.Tablespace
41-
42-
sel := row.Find("td")
43-
44-
for i := range sel.Nodes {
45-
single := sel.Eq(i)
46-
value := cleanTr(single.Text())
47-
if i == 2 {
48-
ts.Database = value
49-
}
50-
if i == 3 {
51-
ts.Name = value
52-
}
53-
if i == 4 {
54-
ts.MaxSize = value
55-
}
56-
if i == 5 {
57-
ts.Total = value
58-
}
59-
if i == 6 {
60-
ts.Used = value
61-
}
62-
if i == 7 {
63-
ts.UsedPerc = value
64-
}
65-
if i == 8 {
66-
ts.Status = value
67-
}
28+
tablespaces := []model.Tablespace{}
29+
scanner := bufio.NewScanner(strings.NewReader(string(cmdOutput)))
30+
31+
for scanner.Scan() {
32+
tablespace := new(model.Tablespace)
33+
line := scanner.Text()
34+
splitted := strings.Split(line, "|||")
35+
if len(splitted) == 9 {
36+
tablespace.Database = strings.TrimSpace(splitted[2])
37+
tablespace.Name = strings.TrimSpace(splitted[3])
38+
tablespace.MaxSize = strings.TrimSpace(splitted[4])
39+
tablespace.Total = strings.TrimSpace(splitted[5])
40+
tablespace.Used = strings.TrimSpace(splitted[6])
41+
tablespace.UsedPerc = strings.TrimSpace(splitted[7])
42+
tablespace.Status = strings.TrimSpace(splitted[8])
43+
44+
tablespaces = append(tablespaces, *tablespace)
6845
}
69-
70-
tbs = append(tbs, ts)
71-
72-
})
73-
74-
return tbs
46+
}
47+
return tablespaces
7548
}

sql/db.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
-- You should have received a copy of the GNU General Public License
1414
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16-
set markup html on
17-
-- set spool on
18-
set lines 200 pages 0 feedback off verify off
16+
set lines 16000 pages 0 feedback off verify off
17+
set colsep "|||"
1918
col owner for a30
2019
col Nome_Acronimo for a8
2120
col segment_name for a60

0 commit comments

Comments
 (0)