IDM Shell Script Adapter

Hello,

I'm having a lot of trouble implementing the shell script adapter for use with a Linux resource.

I cannot use an out of the box adapter.

My approach is to implement Actions for Get User, Create User, Delete User, Modify User, and List All Objects.

Basically List All Objects and Get User will go through the /etc/passwd file and pull out the pertinent data.

I think I need to use an AttrParse as well to figure out which field is which.

Has anyone else done this? Am I doing this correctly? I'm having some trouble with this, specifically, when doing the reconcile, I get all sorts of parsing errors.

Here's some sample action/AttrParsers. They are a bit of a hodgepodge, as I've been doing a lot of trial and error.

Thanks for any help.

<ResourceAction name='Linux-Get All Users Action'>

<ResTypeAction restype='Shell Script' actionType='UnixShell'>

<act>

#!/bin/bash

echo "=====Get All Users Action - `date`" >> log.txt

cat /etc/passwd | grep "/home"> passwd.txt

awk '{print "USERS=" $0}' passwd.txt > passwd-final.txt

cat "Account ID"

cat passwd.txt

exit 0

# exit $DISPLAY_INFO_CODE if there is not a failure, but you want

# the output to be propagated to the UI

</act>

</ResTypeAction>

</ResourceAction>

<ResourceAction name='Linux-Get User Action'>

<ResTypeAction restype='Shell Script' actionType='UnixShell'>

<act>

echo "=====Get User Action - `date`" >> log.txt

echo $WSUSER_accountId >> log.txt

#

if [ "${WSUSER_accountId}xxx" = "xxx" ]; then

echo "WSUSER_accountId environment variable not defined."

exit 129

fi

if [ "${WSRSRC_NAME}xxx" = "xxx" ]; then

echo "WSRSRC_NAME environment variable not defined."

exit 130

fi

echo `grep ^$WSUSER_accountId /etc/passwd | cut -d: -f1` > users.txt

echo `grep ^$WSUSER_accountId /etc/passwd

exit 0

</act>

</ResTypeAction>

</ResourceAction>

<AttrParse name="Linux-List All Objects AttrParse">

<multiLine opt="true">

<collectCsvHeader idHeader='Account ID' nameHeader='Full Name' delim=':' trim='true'/>

<skipLinesUntil/>

<collectCsvLines trim='true' unQuote='true'/>

</multiLine>

</AttrParse>

<AttrParse name="Linux-Get User AttrParse">

<str name="Account ID" trim="true" len="-1"/>

</AttrParse>

[2675 byte] By [jsizzlea] at [2007-11-27 8:10:52]
# 1

The native adapter looks at a lot more than just /etc/passwd. It'll go through your last login logs, and things like that (on solaris, its even more elaborate, with it looking into auths, roles, etc.)

Problem with parsing is that you have to be sure what text the box is echoing in response to your commands. If you are running into parsing errors, the best way to iron them out would be to run the same commands from a prompt (same env as your IDM connecting user). You should be able to reproduce the problem there. In the shell scripts / commands, be sure to account for special characters or anything that may be interpreted by the shell.

I am not sure how legal this is, but decompiling the existing adapter in idmadapter.jar can sometimes be insightful. Someone from Sun would be able to comment better on the legal aspect of this.

Cheers!

Ankush

ankushkapoora at 2007-7-12 19:54:38 > top of Java-index,Web & Directory Servers,Directory Servers...
# 2

Thanks for the suggestion.

I know the out of box adapters do a lot more, I am just not able to use them in this case.

In my easiest, simplest scenario, if I just get the user names out of /etc/passwd and echo them to the Shell Script Adapter, I'll get a list back like this:

username1,

username2,

username3,

root

etc,etc.

The problem I'm having seems to be in my AttrParse.

Since this is just usernames, my AttrParse is just this:

<AttrParse name="Linux-Username AttrParse">

<str name="Account ID" trim="true" len="-1"/>

<skipToEol/>

</AttrParse>

However, this isn't working in the slightest. I get an exception thrown:

com.waveset.util.WavesetException: Unexpected character at index 1

at com.waveset.util.ParseStringCharacterIterator.bypass(ParseStringChara

cterIterator.java:149)

at com.waveset.util.ParseStringCharacterIterator.skipPast(ParseStringCha

racterIterator.java:91)

at com.waveset.util.ParseStringCharacterIterator.getToEol(ParseStringCha

racterIterator.java:175)

at com.waveset.object.AttrParse$StringToken.parse(AttrParse.java:490)

at com.waveset.object.AttrParse.parse(AttrParse.java:1384)

at com.waveset.object.AttrParse.parse(AttrParse.java:1355)

at com.waveset.object.AttrParse.parse(AttrParse.java:1345)

at com.waveset.adapter.ShellScriptResultHandlerAttrParse.getListAllObjec

tsResult(ShellScriptResultHandlerAttrParse.java:629)

at com.waveset.adapter.ShellScriptResourceAdapter.getListAllObjectsResul

t(ShellScriptResourceAdapter.java:1175)

at com.waveset.adapter.GenericScriptResourceAdapter.listAllObjects(Gener

icScriptResourceAdapter.java:1396)

at com.waveset.adapter.ShellScriptResourceAdapter.getAccountIterator(She

llScriptResourceAdapter.java:701)

at com.waveset.adapter.ShellScriptResourceAdapter.getAccountIterator(She

llScriptResourceAdapter.java:1242)

at com.waveset.adapter.ResourceAdapterProxy.getAccountIterator(ResourceA

dapterProxy.java:920)

at com.waveset.recon.ResourceContext.iterateResourceAccounts(ResourceCon

text.java:1129)

at com.waveset.recon.ReconTask$ResourceThread.examineResource(ReconTask.

java:846)

at com.waveset.recon.ReconTask$ResourceThread.reconcileResource(ReconTas

k.java:714)

at com.waveset.recon.ReconTask$ResourceThread.run(ReconTask.java:540)

WavesetException: Unexpected character at index 2

com.waveset.util.WavesetException: Unexpected character at index 2

at com.waveset.util.ParseStringCharacterIterator.bypass(ParseStringChara

cterIterator.java:149)

at com.waveset.util.ParseStringCharacterIterator.skipPast(ParseStringCha

racterIterator.java:91)

at com.waveset.util.ParseStringCharacterIterator.getToEol(ParseStringCha

racterIterator.java:175)

at com.waveset.object.AttrParse$StringToken.parse(AttrParse.java:490)

at com.waveset.object.AttrParse.parse(AttrParse.java:1384)

at com.waveset.object.AttrParse.parse(AttrParse.java:1355)

at com.waveset.object.AttrParse.parse(AttrParse.java:1345)

at com.waveset.adapter.ShellScriptResultHandlerAttrParse.getListAllObjec

tsResult(ShellScriptResultHandlerAttrParse.java:629)

at com.waveset.adapter.ShellScriptResourceAdapter.getListAllObjectsResul

t(ShellScriptResourceAdapter.java:1175)

at com.waveset.adapter.GenericScriptResourceAdapter.listAllObjects(Gener

icScriptResourceAdapter.java:1396)

at com.waveset.adapter.ShellScriptResourceAdapter.getAccountIterator(She

llScriptResourceAdapter.java:701)

at com.waveset.adapter.ShellScriptResourceAdapter.getAccountIterator(She

llScriptResourceAdapter.java:1242)

at com.waveset.adapter.ResourceAdapterProxy.getAccountIterator(ResourceA

dapterProxy.java:920)

at com.waveset.recon.ResourceContext.iterateResourceAccounts(ResourceCon

text.java:1129)

at com.waveset.recon.ReconTask$ResourceThread.examineResource(ReconTask.

java:846)

at com.waveset.recon.ReconTask$ResourceThread.reconcileResource(ReconTas

k.java:714)

at com.waveset.recon.ReconTask$ResourceThread.run(ReconTask.java:540)

WavesetException: Unexpected character at index 3

com.waveset.util.WavesetException: Unexpected character at index 3

at com.waveset.util.ParseStringCharacterIterator.bypass(ParseStringChara

cterIterator.java:149)

at com.waveset.util.ParseStringCharacterIterator.skipPast(ParseStringCha

racterIterator.java:91)

at com.waveset.util.ParseStringCharacterIterator.getToEol(ParseStringCha

racterIterator.java:175)

at com.waveset.object.AttrParse$StringToken.parse(AttrParse.java:490)

at com.waveset.object.AttrParse.parse(AttrParse.java:1384)

at com.waveset.object.AttrParse.parse(AttrParse.java:1355)

at com.waveset.object.AttrParse.parse(AttrParse.java:1345)

at com.waveset.adapter.ShellScriptResultHandlerAttrParse.getListAllObjec

tsResult(ShellScriptResultHandlerAttrParse.java:629)

at com.waveset.adapter.ShellScriptResourceAdapter.getListAllObjectsResul

t(ShellScriptResourceAdapter.java:1175)

at com.waveset.adapter.GenericScriptResourceAdapter.listAllObjects(Gener

icScriptResourceAdapter.java:1396)

at com.waveset.adapter.ShellScriptResourceAdapter.getAccountIterator(She

llScriptResourceAdapter.java:701)

at com.waveset.adapter.ShellScriptResourceAdapter.getAccountIterator(She

llScriptResourceAdapter.java:1242)

at com.waveset.adapter.ResourceAdapterProxy.getAccountIterator(ResourceA

dapterProxy.java:920)

at com.waveset.recon.ResourceContext.iterateResourceAccounts(ResourceCon

text.java:1129)

at com.waveset.recon.ReconTask$ResourceThread.examineResource(ReconTask.

java:846)

at com.waveset.recon.ReconTask$ResourceThread.reconcileResource(ReconTas

k.java:714)

at com.waveset.recon.ReconTask$ResourceThread.run(ReconTask.java:540)

WavesetException: Unexpected character at index 5

com.waveset.util.WavesetException: Unexpected character at index 5

And over and over again for each character.

This is the crux of my current problem. Any suggestions on how to fix my Attribute Parser?

jsizzlea at 2007-7-12 19:54:38 > top of Java-index,Web & Directory Servers,Directory Servers...