Skip to content

Commit

Permalink
Merge pull request #15 from PluginsOCSInventory-NG/update_dbinstances
Browse files Browse the repository at this point in the history
multiple instances retrieval + fix column name displayed as computer
  • Loading branch information
fbomj authored Apr 17, 2022
2 parents 44f59ee + 52aae03 commit 8696a77
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 74 deletions.
4 changes: 2 additions & 2 deletions APACHE/Map.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ $DATA_MAP{dbinstances} = {
multi => 1,
auto => 1,
delOnReplace => 1,
sortBy => 'NAME',
sortBy => 'VERSION_NAME',
writeDiff => 0,
cache => 0,
fields => {
PUBLISHER => {},
NAME => {},
VERSION_NAME => {},
VERSION => {},
EDITION => {},
INSTANCE => {}
Expand Down
134 changes: 67 additions & 67 deletions agent/Windows/runningDatabaseInstances.ps1
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
$edition = "Unknown"
$version = "Unknown"

If (-not (test-path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server'))
{
exit
}

$inst = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances

$xml += "<SOFTWARES>"
$xml += "<PUBLISHER>OCS Inventory Team</PUBLISHER>"
$xml += "<NAME>DBInstances</NAME>"
$xml += "<VERSION>2.0</VERSION>"
$xml += "<COMMENTS>DBInstances plugin</COMMENTS>"
$xml += "</SOFTWARES>"

foreach ($i in $inst)
{
$instanceFullName = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$i
$instanceName = $instanceFullName

if($instanceFullName.Contains(".")){
$instanceSplitted = $instanceFullName.Split(".")
$instanceName = $instanceSplitted.Get(1)
}

$publisher = "Microsoft Corporation"
$edition = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceFullName\Setup").Edition
$version = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceFullName\Setup").Version

if($version.StartsWith("10")){
$serverName = "Microsoft SQL Server 2008"
}elseif($version.StartsWith("10.5")){
$serverName = "Microsoft SQL Server 2008 R2"
}elseif($version.StartsWith("11")){
$serverName = "Microsoft SQL Server 2012"
}elseif($version.StartsWith("12")){
$serverName = "Microsoft SQL Server 2014"
}elseif($version.StartsWith("13")){
$serverName = "Microsoft SQL Server 2016"
}elseif($version.StartsWith("14")){
$serverName = "Microsoft SQL Server 2017"
}elseif($version.StartsWith("15")){
$serverName = "Microsoft SQL Server 2019"
}else{
$serverName = "Microsoft SQL Server " + $version
}

$xml += "<DBINSTANCES>"
$xml += "<PUBLISHER>Microsoft Corporation</PUBLISHER>"
$xml += "<NAME>" + $serverName + "</NAME>"
$xml += "<VERSION>" + $version + "</VERSION>"
$xml += "<EDITION>" + $edition + "</EDITION>"
$xml += "<INSTANCE>" + $instanceName + "</INSTANCE>"
$xml += "</DBINSTANCES>"

$xml += "<SOFTWARES>"
$xml += "<PUBLISHER>Microsoft Corporation</PUBLISHER>"
$xml += "<NAME>" + $serverName + "</NAME>"
$xml += "<VERSION>" + $version + "</VERSION>"
$xml += "<COMMENTS>DBInstances plugin</COMMENTS>"
$xml += "</SOFTWARES>"

}

echo $xml
$edition = "Unknown"
$version = "Unknown"

If (-not (test-path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server'))
{
exit
}

$inst = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL' | Select *

$xml += "<SOFTWARES>"
$xml += "<PUBLISHER>OCS Inventory Team</PUBLISHER>"
$xml += "<NAME>DBInstances</NAME>"
$xml += "<VERSION>2.0</VERSION>"
$xml += "<COMMENTS>DBInstances plugin</COMMENTS>"
$xml += "</SOFTWARES>"

$inst.PSObject.Properties | ForEach-Object {
if (-not $_.Name.StartsWith('PS')) {
$instanceFullName = $_.Value
$instanceName = $instanceFullName
if($instanceFullName.Contains(".")){
$instanceSplitted = $instanceFullName.Split(".")
$instanceName = $instanceSplitted.Get(1)
}

$publisher = "Microsoft Corporation"
$edition = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceFullName\Setup").Edition
$version = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceFullName\Setup").Version

if($version.StartsWith("10")){
$serverName = "Microsoft SQL Server 2008"
}elseif($version.StartsWith("10.5")){
$serverName = "Microsoft SQL Server 2008 R2"
}elseif($version.StartsWith("11")){
$serverName = "Microsoft SQL Server 2012"
}elseif($version.StartsWith("12")){
$serverName = "Microsoft SQL Server 2014"
}elseif($version.StartsWith("13")){
$serverName = "Microsoft SQL Server 2016"
}elseif($version.StartsWith("14")){
$serverName = "Microsoft SQL Server 2017"
}elseif($version.StartsWith("15")){
$serverName = "Microsoft SQL Server 2019"
}else{
$serverName = "Microsoft SQL Server " + $version
}


$xml += "<DBINSTANCES>"
$xml += "<PUBLISHER>Microsoft Corporation</PUBLISHER>"
$xml += "<VERSION_NAME>" + $serverName + "</VERSION_NAME>"
$xml += "<VERSION>" + $version + "</VERSION>"
$xml += "<EDITION>" + $edition + "</EDITION>"
$xml += "<INSTANCE>" + $instanceName + "</INSTANCE>"
$xml += "</DBINSTANCES>"

$xml += "<SOFTWARES>"
$xml += "<PUBLISHER>Microsoft Corporation</PUBLISHER>"
$xml += "<VERSION_NAME>" + $serverName + "</VERSION_NAME>"
$xml += "<VERSION>" + $version + "</VERSION>"
$xml += "<COMMENTS>DBInstances plugin</COMMENTS>"
$xml += "</SOFTWARES>"
}
}

echo $xml
4 changes: 2 additions & 2 deletions agent/Windows/runningDatabaseInstances.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ If Err = 0 Then
' On garde <DBINSTANCES> pour le côté ergonomique sur l'interface Web OCS
Result = "<DBINSTANCES>" & VbCrLf
Result = Result & "<PUBLISHER>Microsoft Corporation</PUBLISHER>" & VbCrLf
Result = Result & "<NAME>" & strSQLName & strServicePack & "</NAME>" & VbCrLf
Result = Result & "<VERSION_NAME>" & strSQLName & strServicePack & "</VERSION_NAME>" & VbCrLf
Result = Result & "<VERSION>" & strVersion & "</VERSION>" & VbCrLf
Result = Result & "<EDITION>" & strEdition & "</EDITION>" & VbCrLf
Result = Result & "<INSTANCE>" & strServiceName & "</INSTANCE>" & VbCrLf
Expand Down Expand Up @@ -387,7 +387,7 @@ If Err = 0 Then
' Ecrit les données de sortie en XML dans la table Dbinstances
Result = "<DBINSTANCES>" & VbCrLf &_
Result = Result & "<PUBLISHER>Microsoft Corporation</PUBLISHER>" & VbCrLf &_
Result = Result & "<NAME>" & strDisplayName & "</NAME>" & VbCrLf &_
Result = Result & "<VERSION_NAME>" & strDisplayName & "</VERSION_NAME>" & VbCrLf &_
Result = Result & "<INSTANCE>Aucun service</INSTANCE>" & VbCrLf &_
Result = Result & "</DBINSTANCES>"
WScript.Echo Result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
echo open_form($form_name);
$list_fields = array(
'PUBLISHER' => 'PUBLISHER',
'NAME' => 'NAME',
'VERSION_NAME' => 'VERSION_NAME',
'VERSION' => 'VERSION',
'EDITION' => 'EDITION',
'INSTANCE' => 'INSTANCE'
Expand Down
4 changes: 2 additions & 2 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ function extension_install_runningdatabaseinstances()
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`HARDWARE_ID` INT(11) NOT NULL,
`PUBLISHER` VARCHAR(255) NULL DEFAULT NULL,
`NAME` VARCHAR(255) NULL DEFAULT NULL,
`VERSION_NAME` VARCHAR(255) NULL DEFAULT NULL,
`VERSION` VARCHAR(255) NULL DEFAULT NULL,
`EDITION` VARCHAR(255) NULL DEFAULT NULL,
`INSTANCE` VARCHAR(255) NULL DEFAULT NULL,
PRIMARY KEY (`ID`,`HARDWARE_ID`),
INDEX `NAME` (`NAME`),
INDEX `VERSION_NAME` (`VERSION_NAME`),
INDEX `VERSION` (`VERSION`),
INDEX `ID` (`ID`)
) COLLATE='utf8_general_ci' ENGINE=INNODB ROW_FORMAT=DEFAULT;");
Expand Down

0 comments on commit 8696a77

Please sign in to comment.