Skip to content

Tag: <attribute> - Extracts User Info in the user_show_all Task

Definition

The <attribute> tag is used only in the 'user_show_all task'. It is used to specify the attributes of a dataset that will be passed back from the tasks, containing various bits of information about each discovered user.

This tag has the following attributes:

Parameters

  • name (str) : The name of the parameter whose current value is to be read.

  • value (str) : Sets the name of the attribute to a fixed string value. Note this value does NOT support substitutions.

  • word_nr (int) : Specifies the word number on the line to extract. Count starts from 1.

  • line_nr (int) : Specifies the line to extract from. Count starts from 0.

  • regex (str) : Specifies a regex with a capturing groups to extract the required value.

  • elem (str) : Used to extract a specific XML element value. Set this to the name of the tag to be read.

Example: Simplest Use

If the command only returns one single line with just one word and this is what you want to extract then you can use:

1
<attribute name="name"/>

This extracts the entire result form the parent command, and places the result in the name field.

Example: Extract a specific word

When a command returns a line of text that is separated by spaces, each word can be extracted using the 'word_nr' or word number attribute. Simply specify the word position number required, the count starts from 1.

For example:

1
<attribute name="name" word_nr="1"/>

Example: Extract from a specific line

As well as specific words, if the device replies with a multi line reply, an individual line can be selected with 'line_nr' or line number. It is often used in conjunction with 'word_nr', like this:

1
<attribute name="name" line_nr="1" word_nr="1"/>

If not specified, the default is the first line or line_nr="0".

Example: Extract using a regex capturing group

More complex extractions be can done with regex capturing groups. Say you have a username line separated with colons instead of spaces (like in a Linux password file) you can use this:

1
<attribute name="name" regex="^.*user\s(.*)\s{$"/>

Only one capturing group can be used.

Example: Extracting an XML element

Used in conjunction with the XML settings in the parent command tag, you can extract element text from XML. Consider this XML output::

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
   <Results>
      <Row>
         <User>admin</User>
         <Role>Admin</Role>
      </Row>
      <Row>
         <User>alice</User>
         <Role>Admin</Role>
      </Row>
      <Row>
         <User>bob</User>
         <Role>Admin</Role>
      </Row>
   <Results>

The user names can be extracted with:

1
2
3
<command entry_elem="Row" format="xml_dataset">show users -output xml
   <attribute elem="User" name="name"/>
</command>

Parent Tags

Child Tags

  • None