cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
K_JTRAY
Engaged Sweeper
EDIT: Added details, edited requirement and on a related note, you could also reuse this same code (below) for any terminal command and easily parse the resulting Array to get additional info; for instance, I had to create a clone of this code to query for "system_profiler" so I could check to see which Macs had SSDs or not. We are invested in Lansweeper and I want to feel like I can help to add features to the core. And, it seems the Lansweeper developers are already going to implement stuff like that eventually, although I would make a strong case for displaying Mac userdata even IF it may duplicate/conflict with user data from Active Directory; worst case scenario, just disconnect the two, perhaps? (and the power on/off time charts like PC assets have would be VERY nice to have here as well).

MacUserlistGetter.exe for Lansweeper custom action - (AutoIT v3.3.12.0)

Displays a GUI window containing a list the recent users logged into the Mac asset (via the Mac "last" command) when launched as a Lansweeper custom action. Make sure you read my REQUIREMENTS section below.

Dear Lansweeper developers, PLEASE use my code, if needed, to bring this userlist retrieval feature (for Mac assets) into Lansweeper core! All you need to do is parse the Array this EXE generates (well, technically a .tmp file in %temp% in this version) and write that to the database - or you can just hire me as a Mac interface developer Either way, I didn't want to write the AutoIT SQL connector code (even though it would be fairly easy) to hack-import these results into the Lansweeper database - we need to use your code that scans on a schedule and writes to the correct database columns already. My code that rescans the asset every 15 minutes shouldn't even be there, really, and that capability should reside in Lansweeper core. It does however teach a few onlookers about the versatility of AutoIT. Also, you need to read the REQUIREMENTS section below if you want to use the EXE, so go ahead and read that.

I have also included a sample of the userlist GUI you will see pop up after clicking the "Mac Userlist Getter" custom action on your Lansweeper sidebar. By the way, make sure you read my REQUIREMENTS section below...

Ask me if you have any other ideas! I would love to help add more valuable features to the community.

MY SOURCE CODE, REQUIREMENTS, AND HELPFUL COMMENTS FOLLOWS BELOW:
-----------------------------------------------------------------------------------------------



;MacUserlistGetter for Lansweeper custom action - AutoIT v3.3.12.0
;-------------------------------------------------------------------------------------------------------------------
;DESCRIPTION: When launched from a Lansweeper action, this standalone EXE will display a window containing a list of
;the recent users logged into the specified Macintosh computer. If the Mac asset is offline, a choice to rescan the
;asset every 15 minutes is presented.
;-------------------------------------------------------------------------------------------------------------------
;DISCLAIMER: USE THIS CODE AT YOUR OWN RISK!; You are hereby responsible for any incorrectly modified derivatives
;thereof and are required to reuse this code henceforth in as many places and forms as you see fit, with or without
;credit to the "original" author(s), despite the fact there is no such thing as an "original" author. Any vehement
;opposition to copyright contained in this notice is not meant to promote or incite the idea that copyright is an
;archaic concept ultimately contradictory to societal progress, except in those case(s) for which it obviously is.
;-------------------------------------------------------------------------------------------------------------------
;REQUIREMENTS AND NOTES:
;-Lansweeper action string formatted as below usage section describes
;-SSH enabled and working on the Macintosh asset (described in Lansweeper documentation; enable "Remote Login" for your username in "Sharing" options on the Mac asset)
;-ALL below EXE placed in your Lansweeper Action Path (check your settings page and usage below)
;-MacUserlistGetter.exe in your Lansweeper Actions folder (compiled yourself using below source code and AutoIT or downloaded from me)
;-putty.exe in your Lansweeper Actions folder (included with Lansweeper, but latest version download from: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)
;-plink.exe in your Lansweeper Actions folder (downloaded from: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)
;-pageant.exe in your Lansweeper Actions folder (EDIT: may not be required: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)

;LANSWEEPER ACTION STRING USAGE:
; {actionpath}MacUserlistGetter.exe {actionpath} {ipaddress} "OPTIONAL_SSH-username" "OPTIONAL_SSH-password"
;
;REMARKS ON VARIABLES/ARGUMENTS IN THE ACTION STRING:
;Do not have spaces in your Lansweeper action path! That's bad!
;Variables {actionpath} and {ipaddress} are MANDATORY
;If optional "SSH-username" (quotes included) IS NOT provided here in the action string, script will prompt for user and password input at runtime
;If optional "SSH-username" (quotes included) IS provided and SSH-password IS NOT provided, script will only prompt for password input at runtime

#include <Array.au3> ; needed only for userlist Array output in a nice GUI

Global $LansweeperActionPath = ""
Global $IPaddress = ""
If $CmdLine[0] < 2 Then ; first two arguments to this EXE
MsgBox(32, "Userlist Query Aborted", "I must abort due to missing actionpath + IP Address; these should be the first + second arguments you pass to me...")
Exit
Else
$LansweeperActionPath = $CmdLine[1] ; lansweeper action path only needed to launch plink.exe
$IPaddress = $CmdLine[2] ; IP address of Mac asset is needed
EndIf

Ping($IPaddress) ; ping asset ip address to check if online
If @error Then
Sleep(1000) ; wait a second before retrying
Ping($IPaddress) ; ping asset ip address again just to verify offline status
If @error Then
If MsgBox(48+4, "Asset currently offline?", "I was not able to query this asset; would you like for me to RETRY this query EVERY 15 MINUTES until I get that list for you?") = 6 Then ; if Yes, then start retrying ping
While 1
Sleep(900000) ; wait 15 minutes before next asset ping retry
Ping($IPaddress) ; ping the asset again now
If @error Then ContinueLoop ; if asset is still offline, continue waiting
GetAssetUserlist() ;asset should be online now if ping was successful, so get the userlist now
WEnd
Else
Exit ; if No/Cancel, then exit script
EndIf
EndIf
EndIf
GetAssetUserlist() ; asset should be online, so get the userlist now

Func GetAssetUserlist()
Local $SSHusername = ""
If $CmdLine[0] < 3 Then ; username is optional; prompt now if not included in action string
$SSHusername = InputBox("SSH Username Required", "I couldn't find your SSH username in the action string; please enter the SSH username for this asset:", "", " M")
If @error Then
MsgBox(32, "Userlist Query Aborted", "I must abort due to missing username; this could be the third argument you pass to me...")
Exit
EndIf
Else
$SSHusername = $CmdLine[3] ; else, username was provided as third command line argument
EndIf

Local $SSHpassword = ""
If $CmdLine[0] < 4 Then ; password is also optional; prompt now if not included in action string
Local $SSHpassword = InputBox("SSH Password Required", "I couldn't find your SSH password in the action string; please enter the SSH password for this asset:", "", "*M")
If @error Then
MsgBox(32, "Userlist Query Aborted", "I must abort due to missing password; this could be the fourth argument you pass to me...")
Exit
EndIf
Else
$SSHpassword = $CmdLine[4] ; else, password was provided as fourth command line argument
EndIf

RunWait(@ComSpec & " /c echo y | " & $LansweeperActionPath & "plink.exe" & " -ssh " & $SSHusername & "@" & $IPaddress & " exit", "", @SW_HIDE) ; auto-accept host key for this asset then exit session
Sleep(1000) ; wait a second before connecting back to asset
RunWait(@ComSpec & " /c " & $LansweeperActionPath & "plink.exe -ssh -pw " & $SSHpassword & " " & $SSHusername & "@" & $IPaddress & " last > " & @TempDir & "\userlist_" & $IPaddress & ".tmp", "", @SW_HIDE) ; run the OSX "last" command and write all session output to local temp file
Local $SSHsession_output = FileReadToArray(@TempDir & "\userlist_" & $IPaddress & ".tmp") ; read session output to a 1D array, one line per element
FileDelete(@TempDir & "\userlist_" & $IPaddress & ".tmp") ; don't leave random userlist files in %temp%
_ArrayDisplay($SSHsession_output, "Asset User Activity - Apple Mac @ " & $IPaddress) ; show session output in a nice GUI
Exit
EndFunc
1 REPLY 1
Susan_A
Lansweeper Alumni
My apologies for not responding sooner, but I just wanted to thank K_JTRAY for this custom action and all of the information he provided. I'm sure other forum users will find this useful.

We have had some customers ask about user data for non-Windows machines, so I'm sure this is something that will be built into the software eventually. It's just a matter of development finding the time I think. We are currently completely focused on getting our help desk ready for our beta testers.