How to use a token for a rex in Splunk? - splunk

I have a token $token_rex$ set up as follows in the dashboard:
<set>mvjoin(mvmap('token_keywords_mv',"(?<".'token_keywords_mv'.">".'token_keywords_mv'."+?)"), "|")</set>
token_keyrowrds_mv is basically the following:
lorem
ipsum
situs
The resulting token looks like this:
(?<lorem>lorem+?)|(?<ipsum>ipsum+?)|(?<situs>situs+?)
The query I am trying to run is as follows:
index=* | rex field _raw "(?i)".$token_rex$
Ideally the above should be rendered like so:
index=* | rex field _raw "(?i)(?<lorem>lorem+?)|(?<ipsum>ipsum+?)|(?<situs>situs+?)"
I have tried using the token filters $token_rex|s$ and $token_rex|n$ but neither work. I have even tried to return the value from a subsearch:
index=* | rex field _raw [| makeresults | eval string_rex=$token_rex$ | return $token_rex]
Update: Found out that the token is being given as verbose to the rex command. My token is set as follows:
<set token="token_rex">mvjoin(mvmap('token_keywords_mv',"(?>".'token_keywords_mv'."<".'token_keywords_mv'."+?)"), "|")</set>
When I used it as ... | rex field=_raw '(?i)$token_rex$' it gives me the following error:
Error in 'rex' command: Encountered the following error while compiling the regex ''(?i)mvjoin(mvmap('token_keywords_mv'': Regex: missing closing parenthesis.
When I set it as the value directly, however, it works:
<set token="token_rex">(?<lorem>lorem+?)|(?<ipsum>ipsum+?)|(?<situs>situs+?)</set>
Update: Here's a sample dashboard.
<dashboard theme="dark">
<init>
<set token="token_keywords_mv">split("lorem,ipsum,situs", ",")</set>
<set token="token_keywords_starred">"*".mvjoin($token_keywords_mv$, "* OR *")."*"</set>
<set token="token_rex">"(?i)".mvjoin(mvmap('token_keywords_mv', "(?<".'token_keywords_mv'.">".'token_keywords_mv'."+?)"), "|")</set>
<set token="token_raw">(?<lorem>lorem+?)|(?<ipsum>ipsum+?)|(?<situs>situs+?)</set>
</init>
<label>Test Search</label>
<description>Multivalue</description>
<row>
<panel>
<table>
<search>
<query>index=*
[| makeresults
| eval string_search=$token_keywords_starred$
| return $string_search]
| rex field=_raw $token_raw|s$
| stats count(lorem) AS Lorem, count(ipsum) AS Ipsum, count(situs) AS Situs
| eval header="Count"
| transpose column_name="String" header_field=header</query>
<earliest>-24h#h</earliest>
<latest>now</latest>
</search>
<option name="drilldown">none</option>
<option name="refresh.display">progressbar</option>
</table>
</panel>
</row>
<row>
<panel>
<table>
<title>ECHO</title>
<search>
<query>| localop
| makeresults
| eval token_keywords_starred=$token_keywords_starred$, token_keywords_mv=$token_keywords_mv$, token_rex=$token_rex$, token_raw=$token_raw|s$</query>
<earliest>-24h#h</earliest>
<latest>now</latest>
</search>
<option name="drilldown">none</option>
<option name="refresh.display">progressbar</option>
</table>
</panel>
</row>
</dashboard>
If any other token replaces $token_raw|s$, there will be an error. Using Splunk 8.0.3.

When I try to reproduce your results with this dashboard code:
<form>
<label>test</label>
<fieldset submitButton="false">
<input type="text" token="token_rex">
<label>field1</label>
</input>
</fieldset>
<row>
<panel>
<event>
<title>test</title>
<search>
<query>| makeresults | eval _raw="lorem ipsum dolor"
| rex "(?i)$token_rex$"
| table lorem ipsum situs</query>
<earliest>$earliest$</earliest>
<latest>$latest$</latest>
</search>
<option name="refresh.display">progressbar</option>
</event>
</panel>
</row>
</form>
I get this optimized search (as reported by Job Inspector):
| makeresults | rex field=_raw "(?i)(?<lorem>lorem+?)|(?<ipsum>ipsum+?)|(?<situs>situs+?)"
It looks like the concatenation is not needed.
Update: Change all the set tags to eval and use mvzip instead of mvmap. The set tag does not compute, while the eval tag does.
<eval token="token_keywords_mv">split("lorem,ipsum,situs", ",")</eval>
<eval token="token_keywords_starred">"*".mvjoin($token_keywords_mv$, "* OR *")."*"</eval>
<eval token="token_rex">"(<".mvjoin(mvzip('token_keywords_mv','token_keywords_mv',">"),"+?)|(?<")."+?)"</eval>
<set token="token_raw">(?<lorem>lorem+?)|(?<ipsum>ipsum+?)|(?<situs>situs+?)</set>

Related

selenium ide extract text from input tag [value attribute]

I am using selenium IDE for writing test case and I am trying to extract content in value attribute of below tag
<div id="inputcontainer_f-5" class="FGIC" style="max-width:none;"><input type="text" autocomplete="off" name="f-5" id="f-5" class="dummyclass FastEvtFieldFocus" value="TEXT_I_WANT_TO_GET" readonly="readonly" spellcheck="true" tabindex="-1" style="">
</div>
My selenium IDE code
comment | Target | value
store text | xpath=//input[#id='f-3'] | EXTRATCED_CONTENT
echo | ${EXTRATCED_CONTENT}
Result : I am getting empty string
echo : ""
If i try to change the xpath as xpath=//input[#id='f-3']/#value I am getting following error
storeText on xpath=//input[#id='f-5']/#value with value EXTRATCED_CONTENT Failed:
The result of the xpath expression "//input[#id='f-5']/#value" is: [object Attr]. It should be an element.
How do i extract and store TEXT_I_WANT_TO_GET in variable EXTRATCED_CONTENT and echo it
Thanks
Jk
Try this below.
//input[#id='f-3']#value

ATG - One to Many mapping and list property results

I am trying to do some I supposed to be very simple ... but I have some problems.
TABLE PROVINCE:
CODISTPROV NAME SIGPROV
1 MILAN MI
2 ROME RM
3 NAPLES NA
and TABLE COMUNI:
CODISTPROV CODISTCOM DESC_COM
1 1 XX1
1 2 XX2
2 3 YY3
2 4 YY4
3 5 ZZ5
where CODISTPROV in COMUNI is FOREIGN KEY TO PROVINCE.
The xml is
<item-descriptor name="comuniWithSiglaProvincia" writable="false" item-cache-timeout="86400000" item-expire-timeout="604800000">
<table name="province" type="primary" id-column-names="codistprov">
<property name="sigla_provincia" data-type="String" column-name="sigprov" display-name-resource="Sigla provincia"/>
</table>
<table name="comuni" type="multi" id-column-names="codistprov,codistcom" multi-column-name="codistcom">
<property name="listaComuni" data-type="list" component-data-type="String" column-name="desc_com" />
</table>
</item-descriptor>
I'd like to implement this query
SELECT C.DESC_COM,P.SIGPROV
FROM COMUNI C, PROVINCE P
WHERE C.DESC_COM LIKE 'PAR%' AND C.CODISTPROV = P.CODISTPROV;
where PAR are some characters from input.
The code:
RepositoryView view = getTopoAnagraficaRepository().getView("comuniWithSiglaProvincia");
Object params[] = new Object[1];
params[0] = comuneInitialCharacters;
QueryBuilder repositoryBuilder = view.getQueryBuilder();
QueryExpression prop = repositoryBuilder.createPropertyQueryExpression(PROPERTY_LISTA_COMUNI);
QueryExpression value = repositoryBuilder.createConstantQueryExpression(new String(comuneInitialCharacters));
Query query = repositoryBuilder.createPatternMatchQuery(prop, value, QueryBuilder.STARTS_WITH);
listRepItem = view.executeQuery(query); // 19 results
if(listRepItem != null){
for (RepositoryItem item : listRepItem) {
System.out.println("PROV=" + item.getPropertyValue("sigla_provincia")); // it prints correct value
if (item.getPropertyValue("listaComuni") != null) // ArrayIndexOutOfBoundException
[...]
The query return 19 listRepItem (it is correct) but I got ArrayIndexOutOfBoundException in the last line above, when I try to access the sublist.
Any hints?
What is the correct way to access a property value which is a list?
For example with the data above, if input characters were 'XX' I should have as results
XX1 MI
XX2 MI
Thanks
So what I believe you are trying to achieve is represent the below data model in a Repository as follows:
|
|-- Country1
| |
| |------- Province1
| |------- Province2
| |------- Province3
|-- Country2
|
|------- Province4
|------- Province5
|------- Province6
To achieve this in the repository definition you should probably use a set instead of a list. The documentation states:
The multi-column-name attribute ensures that the ordering of the multi-values are maintained. The column specified by the multi-column-name attribute is used for multi-valued properties of data type array, map, and list and is not used for sets (which are unordered). For map type properties, the values in the column specifiedy by the multi-column-name attribute must be a string. For list or array type properties, these values should be an integer or numeric type, and must be sequential.
To achieve this your repository definition for Country would look something like this:
<item-descriptor display-name-resource="Country" use-id-for-path="false" content="false" writable="true" default="true" display-property="name" folder="false" cache-mode="simple" id-separator=":" name="country" >
<table shared-table-sequence="1" name="COUNTRY" id-column-name="id" type="primary">
<property readable="true" queryable="true" hidden="false" backing-map-property="false" name="id" column-name="ID" data-type="string" required="true" writable="true"/>
<property readable="true" queryable="true" display-name="Name" cache-mode="inherit" backing-map-property="false" name="name" column-name="DISPLAY_NAME" data-type="string" required="true" writable="true"/>
</table>
<table shared-table-sequence="1" name="COUNTRY_PROVINCE" id-column-names="COUNTRY_ID" type="multi">
<property readable="true" display-name-resource="provinces" data-type="set" component-item-type="province" required="false" writable="true" queryable="true" cache-mode="inherit" backing-map-property="false" name="provinces" column-name="PROVINCE_ID"/>
</table>
</item-descriptor>
The province repository definition would look something like this:
<item-descriptor display-name-resource="Province" default="false" expert="false" display-property="name" folder="false" id-separator=":" name="province" use-id-for-path="false" content="false" writable="true">
<table shared-table-sequence="1" name="Province" id-column-name="id" type="primary">
<property readable="true" queryable="true" expert="false" hidden="false" cache-mode="inherit" backing-map-property="false" name="id" column-name="ID" data-type="string" required="true" writable="true"/>
<property readable="true" queryable="true" expert="false" hidden="false" display-name="Name" cache-mode="inherit" backing-map-property="false" name="name" column-name="DISPLAY_NAME" data-type="string" required="true" writable="true"/>
</table>
</item-descriptor>
More information can be found in the Oracle Commerce Documentation.

How to add filter specific to each column in SPLUNK dashboard

I am creating a Dashboard from Splunk log
In this dashboard, I want to want to add the filter to each column.
Just by writing into filter text box, data need to be filtered. something like this.
Here is source detail
<dashboard>
<label>dataReportTable</label>
<row>
<panel>
<table>
<search>
<query>index=_internal sourcetype=splunkd source="D:\\Software\\var\\log\\splunk\\splunkd.log"|
dedup _time, message | table _time, message</query>
<earliest>-24h#h</earliest>
<latest>now</latest>
<sampleRatio>1</sampleRatio>
</search>
<option name="count">20</option>
<option name="dataOverlayMode">none</option>
<option name="drilldown">none</option>
<option name="percentagesRow">false</option>
<option name="rowNumbers">false</option>
<option name="totalsRow">false</option>
<option name="wrap">true</option>
</table>
</panel>
</row>
</dashboard>
Like this:
| multisearch
[ |makeresults | eval _time = " Search Time", message = " Search Message" ]
[ YOUR ORIGINAL SEARCH HERE ]
If you need it to be tokenized, then like this:
| multisearch
[ |makeresults | eval _time = " " . $time_token$, message = " " . $message_token$ ]
[ YOUR ORIGINAL SEARCH HERE ]

Issue when using xquery external variables from the command line in BaseX

I have the following query in a XQ file named "consulta.xq"
declare namespace xs = "http://www.w3.org/2001/XMLSchema";
declare variable $word as xs:string+ external;
for $entry in doc("cni_es_cushimariano2008")//e
where $entry//l[matches(., $word)]
return <e>{$entry//r//text()} --> {$entry//l//text()}</e>
My database "cni_es_cushimariano2008" has the following structure/data:
<?xml version="1.0" encoding="UTF-8"?>
<dictionary>
<alphabet>aeiobchjmnñprsty</alphabet>
<section id="main" type="standard">
<!-- cuidarse (de alguien). aamaantsi. -->
<e>
<p>
<l>cuidarse (de alguien)</l>
<r>aamaantsi<s n="verbo intransitivo"/>
<s n="infinitivo"/>
</r>
</p>
</e>
<!-- celoso. aamaantsi. -->
<e>
<p>
<l>celoso</l>
<r>aamaantsi<s n="adjetivo"/>
</r>
</p>
</e>
<!-- traer. aamaantsi. -->
<e>
<p>
<l>traer</l>
<r>aamaantsi<s n="verbo transitivo"/>
<s n="infinitivo"/>
</r>
</p>
</e>
</section>
</dictionary>
I am trying to execute the following command line instruction
$ basex -b$word=celoso consulta.xq
but I don't receive the expected result and receive the following message:
[XPDY0002] No value assigned to $word as xs:string+.
I am not an expert using Basex and XQuery so I will be grateful for any answer that might help me. Thanks in advance.
The $ character presumably is interpreted by your command shell, such that $word does not reach its destination. It might need to be escaped,
$ basex -b\$word=celoso consulta.xq
or even omitted,
$ basex -bword=celoso consulta.xq

How do I conditionally add an id attribute in TAL (PHPTAL)?

I'm creating a form elements template file in PHPTAL. I would like to be able to OPTIONALLY pass in an id attribute for a field...
So far the code looks like this:
<xml>
<tal:block metal:define-macro="text">
<label tal:condition="php: !isset(hideLabel) || isset(hideLabel) && !hideLabel">${field/label}</label>
<input name="${name}" type="text" value="${field/value}" />
<p tal:condition="exists:field/error">${field/error}</p>
</tal:block>
</xml>
This works as advertised. What I'd like to add is something, like
<input name="${name}" tal:attributes="id exists: id $id | $name" value="${field/value}" />
to allow me to optionally pass in an id from the METAL call...
Should I be doing it differently? I've tried using PHP: isset(id) ? $id : NULL and variations thereof, but just end up with an id="0" in the resultant HTML.
Any ideas?
In case anyone else needs it, one working answer is:
<xml>
<tal:block metal:define-macro="text">
<label tal:condition="not: exists:hideLabel">${field/label}</label>
<input name="${name}" tal:attributes="id id | nothing" type="text" value="${field/value}" />
<p tal:condition="exists:field/error">${field/error}</p>
</tal:block>
</xml>
Where passed in variables are id, name, an array named field, and hideLabel .
Note, that I've also managed to simplify the label test to something which I believe is more idiomatically TAL.
Set VAR at a DIV containing the soon to be used element:
div class="" tal:define="VAR context.property"
div class="" tal:attributes="class python:'grid_8 omega' if VAR else 'grid_8 alpha'"
in PHP:
<div id="contentCenter" tal:attributes="id
php:isset(variable)&&isset(variable.property)?'IDVALUE':NULL">