MySQL 서버 설치 검색(Linux)

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

MySQL 서버의 설치를 검색합니다(Linux용). 이 검색은 스크립트를 통해 컴퓨터에 MySQL 서버가 설치되어 있는지를 프로브합니다.

Knowledge Base article:

요약

이 검색 규칙은 Linux 컴퓨터에서 MySQL 서버의 설치를 검색합니다. MySQL 서버 인스턴스는 MySQL CIM 공급자가 설치되고 MySQL 서버 자격 증명이 제공될 때까지 모니터링되지 않습니다. 이 공급자는 "MySQL 서버 CIM 공급자 설치/업그레이드" 작업을 수행하여 운영 콘솔에서 설치할 수 있습니다. MySQL 서버에 대한 자격 증명은 “기본 MySQL 서버 자격 증명 설정” 작업을 수행하여 설정할 수 있습니다.

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>