ManageEngine Asset Scan sh script help or web hook

KyleEricson
Valued Contributor II

This is the default .sh script for ManageEngine Asset Scan. I modified the variables

#!/bin/sh


############ Server details ############

hostName="MSD69"
portNo="443"
protocol="https"

############ Server details ############

SUPPORT="assetexplorer-support@manageengine.com"
PRODUCT="AssetExplorer"

COMPUTERNAME=`hostname`
OUTPUTFILE="$COMPUTERNAME.xml"


main()
{
    echo "##### Scanning Started #####"
        echo "<?xml version="1.0" encoding="UTF-8" ?><DocRoot>" >$OUTPUTFILE
    constructXML "ComputerName" "hostname"
    constructXML "OS_Category" "uname -s"
    echo "<Hardware_Info>" >>$OUTPUTFILE
    constructXML "OS_Category" "sw_vers"
    constructXML "Memory_Information" "sysctl hw.physmem"
    constructXML "Memory_Information" "sysctl hw.usermem"
    constructXML "Memory_Informationw" "sysctl hw.memsize"
    constructXML "Memory_Information" "sysctl vm.swapusage"
    constructXML "Computer_Information" "hostname"
    constructXML "Computer_Information" "hostname -s"
    constructXML "CPU_Information" "system_profiler SPHardwareDataType"
    constructXML "Disk_Space" "df -k"
    constructXML "NIC_Info" "/sbin/ifconfig"
    #-----------Last logged in user name -----------
    constructXML "Last_logged_user" "finger"
    #-------------Chipset, VRAM, Monitor display type, resolution---------------------
    constructXML "Monitoranddisplayinfo" "/usr/sbin/system_profiler SPDisplaysDataType"
    #--------------Sound card -----------------------------
    constructXML "SoundCardinfo" "/usr/sbin/system_profiler SPAudioDataType"         
    #---------------Memory modules----------------------
    constructXML "MemoryInfo" "/usr/sbin/system_profiler SPMemoryDataType"           
    #--------------Physical drives-------------------------
    constructXML "PhysicaldrivesInfo" "/usr/sbin/system_profiler SPParallelATADataType"     
    #--------------Harddisk info if no data is available in SPParallelATADataType------------
    constructXML "HarddrivesInfo" "/usr/sbin/system_profiler SPSerialATADataType"           
    #----------------Printer Info-----------------------
    constructXML "Printer_Info" "/usr/sbin/system_profiler SPPrintersDataType -xml"           
    echo "</Hardware_Info>" >>$OUTPUTFILE
    echo "<Software_Info>" >>$OUTPUTFILE
    constructXML "Installed_Softwares" "system_profiler SPApplicationsDataType"
    echo "</Software_Info>" >>$OUTPUTFILE
    echo "</DocRoot>" >>$OUTPUTFILE
    echo "##### Scanning completed #####"
    #echo $data
    pushData
}

constructXML()
{
    ##Need to replace the < into &lt; , > into &gt; and & into &amp;#####
    echo "<$1><command>$2</command><output><![CDATA[">>$OUTPUTFILE
    eval $2 >> $OUTPUTFILE 2>&1
    echo "]]></output></$1>" >>$OUTPUTFILE
}

pushData()
{
        data=$(cat $OUTPUTFILE)
        eval "type curl > /dev/null 2>&1"

        if [ $? -ne 0 ]
        then
                echo "curl is not installed, so could not post the scan data to $PRODUCT, You can import the  $COMPUTERNAME.xml available in the current directory into $PRODUCT using Stand Alone Workstations Audit. Executing the curl command will lead to the installation."
                exit 1
        fi

    curl --header "Content-Type: text/xml" --data-binary @$OUTPUTFILE "$protocol://$hostName:$portNo/discoveryServlet/WsDiscoveryServlet?COMPUTERNAME=$COMPUTERNAME"
        if [ $? -ne 0 ]
        then
           echo "$PRODUCT is not reachable. You can import the  $COMPUTERNAME.xml available in the current directory into $PRODUCT using Stand Alone Workstations Audit. For further queries, please contact $SUPPORT."
        else
           rm -rf $OUTPUTFILE
           echo "Successfully scanned the system data, Find this machine details in $PRODUCT server."
        fi
}


main $*

but it fails to run. Any ideas or could a webhook do this?

Read My Blog: https://www.ericsontech.com
4 REPLIES 4

tnjamfnationacc
New Contributor

I have a support case on this same script. Haven't made much progress on it though. It doesn't like the CDATA in the script it seems.

joseph_ginstmar
New Contributor

It might be a bit outdated but I've solved this issue by installing outset and dumping the default.sh script in /usr/local/outset/boot-every and login-every folder.

Does the trick for me.

/Joseph

kevinmwhite
New Contributor III
New Contributor III

I just had to deploy this for a customer. In my years I've deployed hundreds of scripts with Jamf, and this is one of the few I've encountered that can't be deployed via Jamf's default Script methods.

The way this vendor architected their script is incompatible with Jamf's default method for running scripts. Specifically, I believe their combined use of $1 and $2 within an echo in the constructXML function is incompatible with Jamf's script running method.

I make it a point to not modify vendor's scripts, so our solution was to simply create a package in Composer that installs the script as-is into the /Library folder. Then Jamf runs the script via an "Execute Command" line added to the default Inventory Update Policy (changed to run once a day). This way both Jamf and Manage Engine are updated at the same time every day.

Can you elaborate on this more? I am currently trying to get SDP to scan our Macs but not having much luck.