Skip to content

Commit 7ab6010

Browse files
authored
Merge pull request #39 from cbiglioli/35-Retrieve_partitioning_information
Retrieve partitioning information
2 parents 457ddce + 25ee328 commit 7ab6010

File tree

13 files changed

+191
-4
lines changed

13 files changed

+191
-4
lines changed

builder/common_builder/oracle_databases.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020 Sorint.lab S.p.A.
1+
// Copyright (c) 2022 Sorint.lab S.p.A.
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -100,6 +100,7 @@ func (b *CommonBuilder) getOracleDB(entry agentmodel.OratabEntry, host model.Hos
100100
database.PDBs = []model.OracleDatabasePluggableDatabase{}
101101
database.Services = []model.OracleDatabaseService{}
102102
database.FeatureUsageStats = []model.OracleDatabaseFeatureUsageStat{}
103+
database.Partitionings = []model.OracleDatabasePartitioning{}
103104

104105
database.Licenses = computeLicenses(database.Edition(), database.CoreFactor(host), host.CPUCores)
105106
}
@@ -172,6 +173,10 @@ func (b *CommonBuilder) getOpenDatabase(entry agentmodel.OratabEntry, hardwareAb
172173
database.Backups = b.fetcher.GetOracleDatabaseBackups(entry)
173174
}, &wg)
174175

176+
utils.RunRoutineInGroup(b.configuration, func() {
177+
database.Partitionings = b.fetcher.GetOracleDatabasePartitionings(entry)
178+
}, &wg)
179+
175180
wg.Wait()
176181

177182
database.Services = []model.OracleDatabaseService{}

fetch/linux/partitioning.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) 2022 Sorint.lab S.p.A.
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
SID=$1
19+
HOME=$2
20+
21+
if [ -z "$SID" ]; then
22+
>&2 echo "Missing SID parameter"
23+
exit 1
24+
fi
25+
if [ -z "$HOME" ]; then
26+
>&2 echo "Missing ORACLE_HOME parameter"
27+
exit 1
28+
fi
29+
30+
LINUX_FETCHERS_DIR=$(dirname "$0")
31+
FETCHERS_DIR="$(dirname "$LINUX_FETCHERS_DIR")"
32+
ERCOLE_HOME="$(dirname "$FETCHERS_DIR")"
33+
34+
export ORAENV_ASK=NO
35+
export ORACLE_SID=$SID
36+
export ORACLE_HOME=$HOME
37+
export PATH=$HOME/bin:$PATH
38+
39+
sqlplus -S "/ AS SYSDBA" < ${ERCOLE_HOME}/sql/partitioning.sql

fetch/windows/win.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,25 @@ function getDbOpt {
489489
}
490490
}
491491

492+
function getDbPartitionings {
493+
param (
494+
[Parameter(Mandatory=$true)]$d
495+
)
496+
if ($d) { $dbs = gwmi -Class Win32_Service | ? { $_.name -match "oracleservice" -and $_.name -match $d } } else { Write-Warning "missing arguments"; throw }
497+
if (!$dbs) { Write "" } #wrong or no instance
498+
else {
499+
$ohome = ($dbs.PathName.Split()[0]).trim("ORACLE.EXE")
500+
$env:ORACLE_SID= $dbs.PathName.Split()[1]
501+
if (!(Test-Path .\sql\opt.sql)) { Write-Warning "file partitioning.sql unavailable!"; throw }
502+
else {
503+
$ar = '-silent / as sysdba @".\sql\partitioning.sql" '+$d
504+
if ( $dbs.state -eq "Running" -and $dbs.status -eq "OK" ) {
505+
Start-Process $ohome\sqlplus -ArgumentList $ar -Wait -NoNewWindow
506+
}
507+
}
508+
}
509+
}
510+
492511
switch($s.ToUpper()) {
493512
"HOST" { getSysinfo }
494513
"FILESYSTEM" { getPartitions }
@@ -507,5 +526,6 @@ switch($s.ToUpper()) {
507526
"ADDM" { getDbADDM $d }
508527
"SEGMENTADVISOR" { getDBSegmentAdvisor $d }
509528
"OPT" { getDbOpt $d }
529+
"PARTITIONING" { getDbPartitionings $d }
510530
Default { Write-Host "wrong switch selection" }
511531
}

fetcher/fetcher.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020 Sorint.lab S.p.A.
1+
// Copyright (c) 2022 Sorint.lab S.p.A.
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -57,6 +57,7 @@ type Fetcher interface {
5757
GetOracleDatabasePDBTablespaces(entry agentmodel.OratabEntry, pdb string) []model.OracleDatabaseTablespace
5858
GetOracleDatabasePDBSchemas(entry agentmodel.OratabEntry, pdb string) []model.OracleDatabaseSchema
5959
GetOracleDatabaseGrantsDba(entry agentmodel.OratabEntry) []model.OracleGrantDba
60+
GetOracleDatabasePartitionings(entry agentmodel.OratabEntry) []model.OracleDatabasePartitioning
6061

6162
// Oracle/Exadata fetchers
6263
GetOracleExadataComponents() []model.OracleExadataComponent

fetcher/linux_fetcher.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ func (lf *LinuxFetcherImpl) GetOracleDatabasePDBSchemas(entry agentmodel.OratabE
287287
return marshal_oracle.Schemas(out)
288288
}
289289

290+
// GetOracleDatabaseTablespaces get
291+
func (lf *LinuxFetcherImpl) GetOracleDatabasePartitionings(entry agentmodel.OratabEntry) []model.OracleDatabasePartitioning {
292+
out := lf.execute("partitioning", entry.DBName, entry.OracleHome)
293+
return marshal_oracle.Partitionings(out)
294+
}
295+
290296
// GetClusters return VMWare clusters from the given hyperVisor
291297
func (lf *LinuxFetcherImpl) GetClusters(hv config.Hypervisor) []model.ClusterInfo {
292298
var out []byte

marshal/oracle/partitionings.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2022 Sorint.lab S.p.A.
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
package oracle
17+
18+
import (
19+
"bufio"
20+
"bytes"
21+
"strings"
22+
23+
"github.com/ercole-io/ercole-agent-rhel5/marshal"
24+
"github.com/ercole-io/ercole-agent-rhel5/model"
25+
)
26+
27+
// Partitionings returns information about database partitionings extracted
28+
// from the partitionings fetcher command output.
29+
func Partitionings(cmdOutput []byte) []model.OracleDatabasePartitioning {
30+
partitionings := []model.OracleDatabasePartitioning{}
31+
scanner := bufio.NewScanner(bytes.NewReader(cmdOutput))
32+
33+
for scanner.Scan() {
34+
partitioning := model.OracleDatabasePartitioning{}
35+
line := scanner.Text()
36+
splitted := strings.Split(line, "|||")
37+
if len(splitted) == 5 {
38+
partitioning.Owner = strings.TrimSpace(splitted[0])
39+
partitioning.SegmentName = strings.TrimSpace(splitted[1])
40+
partitioning.PartitionName = strings.TrimSpace(splitted[2])
41+
partitioning.SegmentType = strings.TrimSpace(splitted[3])
42+
partitioning.Mb = marshal.TrimParseFloat64(splitted[4])
43+
44+
partitionings = append(partitionings, partitioning)
45+
}
46+
}
47+
48+
return partitionings
49+
}

model/oracle_database.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020 Sorint.lab S.p.A.
1+
// Copyright (c) 2022 Sorint.lab S.p.A.
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -60,8 +60,9 @@ type OracleDatabase struct {
6060
FeatureUsageStats []OracleDatabaseFeatureUsageStat `json:"featureUsageStats" bson:"featureUsageStats"`
6161
PDBs []OracleDatabasePluggableDatabase `json:"pdbs" bson:"pdbs"`
6262
Services []OracleDatabaseService `json:"services" bson:"services"`
63-
OtherInfo map[string]interface{} `json:"-" bson:"-"`
6463
GrantDba []OracleGrantDba `json:"grantDba" bson:"grantDba"`
64+
Partitionings []OracleDatabasePartitioning `json:"partitionings" bson:"partitionings"`
65+
OtherInfo map[string]interface{} `json:"-" bson:"-"`
6566
}
6667

6768
var (
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2022 Sorint.lab S.p.A.
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
package model
17+
18+
// OracleDatabasePartitioning holds the informations about a partitioning.
19+
type OracleDatabasePartitioning struct {
20+
Owner string `json:"owner" bson:"owner"`
21+
SegmentName string `json:"segmentName" bson:"segmentName"`
22+
PartitionName string `json:"partitionName" bson:"partitionName"`
23+
SegmentType string `json:"segmentType" bson:"segmentType"`
24+
Mb float64 `json:"mb" bson:"mb"`
25+
}

package/rhel5/ercole-agent.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ install -m 644 package/rhel5/logrotate $RPM_BUILD_ROOT/etc/logrotate.d/ercole-ag
8181
/opt/ercole-agent/fetch/linux/stats.sh
8282
/opt/ercole-agent/fetch/linux/tablespace.sh
8383
/opt/ercole-agent/fetch/linux/tablespace_pdb.sh
84+
/opt/ercole-agent/fetch/linux/partitioning.sh
8485
/opt/ercole-agent/fetch/linux/oracle_running_databases.sh
8586
/opt/ercole-agent/fetch/linux/vmware.ps1
8687
/opt/ercole-agent/fetch/linux/exadata/info.sh
@@ -108,6 +109,7 @@ install -m 644 package/rhel5/logrotate $RPM_BUILD_ROOT/etc/logrotate.d/ercole-ag
108109
/opt/ercole-agent/sql/stats.sql
109110
/opt/ercole-agent/sql/ts.sql
110111
/opt/ercole-agent/sql/ts_pdb.sql
112+
/opt/ercole-agent/sql/partitioning.sql
111113

112114
%changelog
113115
* Mon May 7 2018 Simone Rota <[email protected]>

package/rhel6/ercole-agent.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ chkconfig ercole-agent on
7676
/opt/ercole-agent/fetch/linux/tablespace.sh
7777
/opt/ercole-agent/fetch/linux/tablespace_pdb.sh
7878
/opt/ercole-agent/fetch/linux/oracle_running_databases.sh
79+
/opt/ercole-agent/fetch/linux/partitioning.sh
7980
/opt/ercole-agent/fetch/linux/vmware.ps1
8081
/opt/ercole-agent/fetch/linux/exadata/info.sh
8182
/opt/ercole-agent/fetch/linux/exadata/storage-status.sh
@@ -102,6 +103,7 @@ chkconfig ercole-agent on
102103
/opt/ercole-agent/sql/stats.sql
103104
/opt/ercole-agent/sql/ts.sql
104105
/opt/ercole-agent/sql/ts_pdb.sql
106+
/opt/ercole-agent/sql/partitioning.sql
105107

106108
%changelog
107109
* Mon May 7 2018 Simone Rota <[email protected]>

0 commit comments

Comments
 (0)