MySQL Server Installation Discovery (Linux)

Microsoft.MySQLServer.Installation.ScriptDiscovery.Unix (Discovery)

Discovers installations of MySQL Server (for Linux). This discovery probes the computer with a script to identify installations of MySQL Server

Knowledge Base article:

Summary

This discovery rule discovers installations of MySQL Servers on Linux computers. A MySQL Server instance is not monitored until the MySQL CIM Provider is installed and MySQL Server credentials are provided. This provider can be installed from the Operations Console with the “Install/Upgrade MySQL Server CIM Provider” task. The credentials for the MySQL Server can be set with the “Set Default MySQL Server Credentials” task.

Element properties:

TargetMicrosoft.Linux.Computer
EnabledTrue
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Oss.TimedShellScript.PropertyBag.Discovery.DataSource Default

Source Code:

<Discovery ID="Microsoft.MySQLServer.Installation.ScriptDiscovery.Unix" Target="Linux!Microsoft.Linux.Computer" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.MySQLServer.Installation.Unix"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Oss!Microsoft.Oss.TimedShellScript.PropertyBag.Discovery.DataSource">
<Interval>14400</Interval>
<TargetSystem>$Target/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$</TargetSystem>
<ShellScript>

#!/bin/bash

version=""
version=`mysqld --version |awk '{print $(NF-5)}'`
if [ "$version" = 'on' ]
then
version=`mysqld --version |awk '{print $(NF-8)}'`
elif [ "$version" = 'for' ]
then
version=`mysqld --version |awk '{print $(NF-6)}'`
fi
# rpm/deb package data directory location
if [ -e /var/lib/mysql/ ]
then
datdir="/var/lib/mysql/"
printf "datdir=$datdir,version=$version"

# generic package data directory location
elif [ -e /usr/local/mysql/data/]
then
datadir="/usr/local/mysql/data/"
printf "datdir=$datdir,version=$version"

# tar source data directory location
elif [ -e /usr/local/var/mysql/ ]
then
datadir="/usr/local/var/mysql/"
printf "datdir=$datdir,version=$version"
fi

</ShellScript>
<ScriptArguments/>
<Timeout>60</Timeout>
<UserName>$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/UserName$</UserName>
<Password>$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/Password$</Password>
<PSScriptName>ParseOutput.ps1</PSScriptName>
<PSScriptBody>
param([string]$StdOut,[string]$StdErr,[string]$ReturnCode)

if($StdOut -like "*datdir*"){
$api = New-Object -ComObject 'MOM.ScriptAPI'
$bag = $api.CreatePropertyBag()

$arProps=$stdOut.Split(",")
foreach ($prop in $arProps) {
$PropName=$prop.Split("=")[0]
$PropValue=$prop.Split("=")[1].Replace("`n","")
$bag.AddValue("$PropName","$PropValue")
}
$bag
}
</PSScriptBody>
<FilterExpression>
<RegExExpression>
<ValueExpression>
<XPathQuery>Property[@Name='datdir']</XPathQuery>
</ValueExpression>
<Operator>MatchesRegularExpression</Operator>
<Pattern>\/.+\/.+\/.+</Pattern>
</RegExExpression>
</FilterExpression>
<ClassId>$MPElement[Name="Microsoft.MySQLServer.Installation.Unix"]$</ClassId>
<InstanceSettings>
<Settings>
<Setting>
<Name>$MPElement[Name='Microsoft.MySQLServer.Installation']/DataDirectory$</Name>
<Value>$Data/Property[@Name='datdir']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='Microsoft.MySQLServer.Installation']/Version$</Name>
<Value>$Data/Property[@Name='version']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='Unix!Microsoft.Unix.Computer']/PrincipalName$</Name>
<Value>$Target/Property[Type="Unix!Microsoft.Unix.Computer"]/PrincipalName$</Value>
</Setting>
</Settings>
</InstanceSettings>
</DataSource>
</Discovery>