Video Screencast Help

Custom Inventory with Autoit (Function)

Created: 24 Aug 2012 • Updated: 24 Aug 2012 | 1 comment
michael cole's picture
0 0 Votes
Login to vote

The attached file is an Autoit function that provides similar functionality to the sample Custom inventory VB Script to send data to the NS. I've provided some background FAQ also.

You will need to:

  • Create your custom Data Class
  • Create an Autoit Script to define your custom inventory
  • Use the attached function and call it at the end of your inventory script
  • Compile your executable and deploy/run to PC's in your environment

(Requires knowledge of Autoit)

WHO WILL BE INTERESTED

Any persons wanting to simplify their custom inventories that already have Autoit knowledge will find this useful. You can deploy an executable to your PC's without worrying about editing the VBS provided in the samples by Symantec, or being constrained to using VBS. Autoit users will know the advantages of it's simplicity and GUI creation. Discounting the 24 lines of code in the function I've got a custom inventory running from 14 lines of code which is cheap on time.

HOW IT WORKS

The function is called with _aexinvsend($array, "Aex_Custom_Inv_MyNewCustomInventory"). You require to have an array of data like Computername, Date, interesting fact no1 etc. You then pass that array to the function along with the name of your custom inventory dataclass (or GUID). The function will loop through all the rows and columns and create the NSE to send off to the NS. This stops you having to edit the VBS in the sample, that part is automated.

WHY NO EXAMPLE CUSTOM INVENTORIES?

I'll post up a couple later - firstly all mine apply to my environment and I'd have to sanitise/rewrite them. And then since I can't post either .AU3 or .exe it looks pretty unglamorous to post up some text files, no matter how many days went into working it out. So on it's own this looks meagre, but in my own opinion it's better than the sample code and does more.

POSSIBLE ADVANTAGES OVER BOXED SAMPLE VERSION

The VBS provided in your Custom Inventory is called 'Custom Inventory - Processor' and is found in: Jobs and Tasks\Samples\Discovery and Inventory\Inventory Samples\Custom. It's tied very much into WMI and writes out lines such as "objDataRow.SetField 0, objInfo.DeviceID". To use this with another inventory object you have to change the script. That gives some room for error and time spent rewriting. Also there is WMI querying involved. Not everyone is au fait with this either, or you may have information pulled from a number of other sources like file lists. When I first started custom inventories these two languages were a mystery to me and the entire thing can be complicated. I remember looking at an autoit script produced by a colleague where it writes out this portion of VBS to a file and executed it and just thought this is too complicated so I set about doing it natively and came up with the attached. I'm a techie, not a developer so excuse any strange code. Anyway, the advantages are that you don't need to rewrite the VBS anymore. The Autoit function will look at your data and loop through all the columns and rows and fire the NSE off to the NS no matter what dimensions it is. All you do is call one line with the array and the custom inventory and its done for you. This allows you to leverage Autoit's GUI creation or your existing skills/scripts.

I'VE ALREADY DONE THIS IN 15 OTHER LANGUAGES AND DON'T NEED AUTOIT

I assume someone must have already written COM interfaces to the Altiris client in other languages but I've not seen them at the time of writing. Nevertheless, this is my one and I'm uploading this to share. I would be interested to see other people's work doing the same things. It's possible no one has done it in Autoit before because everyone uses VB and WMI querying better than myself. It's still valid for what it does and therefore it's possible other techies might find it useful should they not know VBS. And still, I wish someone would document the VB better and perhaps write a function for looping through arrays that I could have copied and pasted years ago ;)

WHAT'S AUTOIT?

I don't sponsor it, but I like it, mainly for writing GUI's. It's a free hgh level scripting language you can find from an internet search. Similar to VBS but geared towards IT automation. The users contribute custom functions that can pretty much do anything that your imagination can think of from a first person shooter to music players. And it's easy to understand if you want to step up from batch files :)

HELP!

PM me in relation to Autoit but note that this isn't supported by Symantec I'm just skinning the cat from right to left as opposed to left to right.

 

Full notes on the function are supplied in the text file as comments, best viewed in SCiTE, a notepad++ type Autoit reader/compiler provided with Autoit.

Comments 1 CommentJump to latest comment

michael cole's picture

I had reason to use this again with a customer, but i wrote out a single row version rather than a function. It might be searchable for those googling. So this is a custom inventory in autoit that picks the modified date of the pagefile.sys. Line two looks nasty , it's just creating the date out of 5 array elements - that's what the function returns.

$file = filegettime("c:\pagefile.sys",0,0)
$file2=""&$file[0]&"-"&$file[1]&"-"&$file[2]&" "&$file[3]&":"&$file[4]&":"&$file[5]&""
$dataclassguid = "filemodified"
local $nse
$nse = ObjCreate ("Altiris.AeXNSEvent")
; GUID below is not to be changed
$nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
$nse.Priority = 1
local $objDCInstance
$objDCInstance = $nse.AddDataClass ($dataclassguid)
local $objDataClass
$objDataClass = $nse.AddDataBlock ($objDCInstance)
local $objDataRow
$objDataRow = $objDataClass.AddRow
$objDataRow.SetField (0, $file2)
;$objDataRow.SetField (1, "test")
$nse.SendQueued

Michael Cole

Principal Business Critical Engineer

Business Critical Services

0
Login to vote