Query condtion check,

I can’t figure out why this query doesn’t work for SunOS…

if name of operating system contains “Linux” AND exist package “splunkforwarder” of rpm then (name of package “splunkforwarder” of rpm, version of package “splunkforwarder” of rpm) as string else if name of operating system contains “SunOS” AND exist name whose ( it as lowercase contains “splunk” ) of pkginfos of pkgdb then ( name of pkginfo “splunkforwarder” of it , version of pkginfo “splunkforwarder” of it ) of pkgdb as string else “SplunkForwarderNotFound”

but this work fine in the query gui but “error” when server don’t have “splunkforwarder” pkg.

if name of operating system contains "Linux"
then ((name of package “splunkforwarder” of rpm, version of package “splunkforwarder” of rpm) as string)
else if name of operating system contains "SunOS"
then ( name of pkginfo “splunkforwarder” of it , version of pkginfo “splunkforwarder” of it ) of pkgdb as string)
else “SplunkForwarderNotFound”

Have you thought of using whose to catch the error? You are in both rpm and pkgdb cases requiring the package to exist.

So something like

package "splunkforwader" whose ( name of it, version of it ) of rpm

This will only give you name and version if the package exists

I think you’re casting ‘pkgdb as string’ too early.

This works like charm

if name of operating system contains "Linux"
then ( if exist package “splunkforwarder” of rpm
then (name of package “splunkforwarder” of rpm, version of package “splunkforwarder” of rpm) as string
else “LinuxSplunkForwarderNotFound,NA” )
else if name of operating system contains "SunOS"
then ( if exist name of pkginfo “splunkforwarder” of pkgdb
then ( name of pkginfo “splunkforwarder” of it , version of pkginfo “splunkforwarder” of it ) of pkgdb as string
else “SunOSSplunkForwarderNotFound,NA” )
else (“N/A”)

Not sure if this approach may also work. Its a method I use when dealing with Linux OS that could be either rpm or debianpackage that I modified to also include pkgdb. I don’t have SunOS to verify if this method works or not.

if (unix of operating system) then ((names of it, versions of it) of packages "splunkforwarder" of (if (exists properties whose (it as string contains "pkgdb:")) then (pkgdb) else (if (exists properties whose (it as string contains "debianpackage:")) then (debianpackage) else (if (exists properties whose (it as string contains "rpm:")) then (rpm) else (ERROR "UnknownPackageInspectorNeeded"))))) else (nothing)