Detectie installatie Apache HTTP-server (Linux)

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

Detecteert installaties van Apache HTTP-server (voor Linux). Deze detectie test de computer met een script om installaties van Apache HTTP-server te herkennen.

Knowledge Base article:

Samenvatting

Deze detectieregel detecteert installaties met Apache HTTP-server voor Linux-servers. Een exemplaar van een Apache HTTP-server wordt pas bewaakt als de CIM-provider voor de Apache-bewaking is geïnstalleerd. Deze module kan worden geïnstalleerd vanaf de Operations-console met de taak Apache CIM-module installeren/upgraden.

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.ApacheHTTPServer.Installation.ScriptDiscovery.Unix" Target="Linux!Microsoft.Linux.Computer" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.ApacheHTTPServer.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
isrpm=`which rpm |grep /rpm|wc -l`
isdpkg=`which dpkg |grep /dpkg |wc -l`

if [ $isrpm -eq 1 ]
then
pkgname=""
pkgFullName=""
version=""
vendor=""
if [ `rpm -q httpd |grep httpd- |wc -l` -eq 1 ]
then
pkgname="httpd"
fi

if [ `rpm -q apache2 |grep apache2-| wc -l` -eq 1 ]
then
pkgname="apache2"
fi

if [ -n "${pkgname}" ]
then
pkgFullName=`rpm -qi $pkgname |grep Name |head -n 1|awk '{print $3}'`
conffile=`rpm -ql $pkgname |grep etc |grep -e 'httpd\.conf$'`
printf "name=$pkgFullName,conffile=$conffile"
fi

fi

if [ $isdpkg -eq 1 ]
then
if [ `dpkg -l apache2 |grep -e '^ii' |wc -l` -eq 1 ]
then
pkgFullName=`dpkg --status apache2 |grep Package |awk '{print $2}'`
conffile="/etc/apache2/apache2.conf"
printf "name=$pkgFullName,conffile=$conffile"
fi
fi

#Check source

if [ -e "/usr/local/apache2/conf/httpd.conf" ]
then
pkgFullName=""
conffile="/usr/local/apache2/conf/httpd.conf"
printf "name=$pkgFullName,conffile=$conffile"
fi

exit 0
</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 "*conffile*"){
$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='conffile']</XPathQuery>
</ValueExpression>
<Operator>MatchesRegularExpression</Operator>
<Pattern>^.+conf$</Pattern>
</RegExExpression>
</FilterExpression>
<ClassId>$MPElement[Name="Microsoft.ApacheHTTPServer.Installation.Unix"]$</ClassId>
<InstanceSettings>
<Settings>
<Setting>
<Name>$MPElement[Name='Microsoft.ApacheHTTPServer.Installation']/PackageName$</Name>
<Value>$Data/Property[@Name='name']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='Microsoft.ApacheHTTPServer.Installation']/ConfFile$</Name>
<Value>$Data/Property[@Name='conffile']$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='Unix!Microsoft.Unix.Computer']/PrincipalName$</Name>
<Value>$Target/Property[Type="Unix!Microsoft.Unix.Computer"]/PrincipalName$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name="System!System.Entity"]/DisplayName$</Name>
<Value>$Data/Property[@Name='conffile']$</Value>
</Setting>
</Settings>
</InstanceSettings>
</DataSource>
</Discovery>