Splunk strptime returning NaN - dashboard

I have a eval on a dashboard that used to work but it stopped and I havent been able to figure out why.
On the dashboard im taking the _time and turning it into a human readable string using strftime(_time, "%m/%d/%Y %H:%M:%S %Z") and that works great. The problem comes in when I try to convert it back later for making a link to a search.
For example:
<eval token="endTimestamp">relative_time(strptime($row.Timestamp$, "%m/%d/%Y %H:%M:%S %Z"), "+30m")</eval>
Used to work and return the unix time that I added 30m to, but now strptime just returns NaN but this is the right format. I've checked out all the Splunk docs and everything looks right but it still is broke.
Any idea what I could be doing wrong?
Here is the snippet from my field row im making:
<condition field="Search">
<eval token="startTimestamp">$row.Timestamp$</eval>
<eval token="endTimestamp">relative_time(strptime($row.Timestamp$, "%m/%d/%Y %H:%M:%S %Z"), "+30m")</eval>
<eval token="corKey">$row.Correlation Key$</eval>
<link target="_blank">search?q=(index=### OR index=###) earliest=$startTimestamp$ latest=$endTimestamp$ correlationKey=$corKey$</link>
</condition>
I have taken out everything but the $row.Timestamp$ and that returns something like 10/03/2021 07:41:27 PDT which is the format that I put into it, I just cant do the reverse. I have copied and pasted the format from the strftime and still no luck converting it back so I can do math on it.
Any suggestions?

I don't think it's anything you're doing wrong... but it does seem that strptime/strftime in the dashboard evals don't seem to like %Z for whatever reason. (My Splunk Cloud stack is on version 8.2.2107.1 )
Doing the roundtrip from epoch to string and back within SPL itself seems to work fine... it's just the (javascript driven) dashboard side that doesn't seem to work quite right with timezone abbreviations.
relative_time from an epoch value works fine... and str[pf]time using UTC offsets with %z format also seems to work (which those could be workarounds for you)
I threw together a quick test dashboard to illustrate such things with the variations in formats to see differences... If you (or someone from your company) is on a current support entitlement, I would log a case for this. (I don't think I see anything related in the published known issues at least).
<dashboard version="1.1">
<label>Teddybear Time Drilldown Test</label>
<row>
<panel>
<table>
<search>
<query>
| makeresults
| eval epoch="1633272087", format=mvappend("%m/%d/%Y %H:%M:%S %Z","%m/%d/%Y %H:%M:%S %z","%m/%d/%Y %H:%M:%S"), Search="Go This Row", Reset="Clear"
| fields - _time
| mvexpand format
| eval Timestamp=strftime(epoch,format), roundtrip=strptime(Timestamp,format)
| table Search, Reset, *
</query>
<earliest>-1s</earliest>
<latest>now</latest>
</search>
<option name="drilldown">cell</option>
<option name="rowNumbers">true</option>
<drilldown>
<condition field="Search">
<eval token="timestamp">$row.Timestamp$</eval>
<eval token="strptime">strptime($row.Timestamp$, $row.format$)</eval>
<eval token="strftime">strftime($row.epoch$, $row.format$)</eval>
<eval token="relative_time">relative_time($row.epoch$,"-30m")</eval>
</condition>
<condition field="Reset">
<unset token="timestamp"/> <unset token="strptime"/> <unset token="strftime"/> <unset token="relative_time"/>
</condition>
</drilldown>
</table>
</panel>
</row>
<row>
<panel>
<title>timestamp</title>
<html>
<h2>$timestamp|s$</h2>
</html>
</panel>
<panel>
<title>strptime</title>
<html>
<h2>$strptime|s$</h2>
</html>
</panel>
<panel>
<title>strftime</title>
<html>
<h2>$strftime|s$</h2>
</html>
</panel>
<panel>
<title>relative_time</title>
<html>
<h2>$relative_time|s$</h2>
</html>
</panel>
</row>
</dashboard>

Related

UiPath selector not working in 'Click Button' Activity

I have the version of UiPath Studio Pro 2020.10.6, and I used Chrome.
I can't find the common Selector on two pages:
First case - failed one
Second case - great one
The selectors offered by the tool are the following:
Case 1:
<html app='chrome.exe' title='Sephora X Coach - Palette de fards à paupières Rexy de SEPHORA COLLECTION ≡ SEPHORA' />
<webctrl id='add-to-cart' tag='BUTTON' type='submit' />
Case 2:
<html app='chrome.exe' title='Kit maquillage des yeux de SEPHORA COLLECTION ≡ SEPHORA' />
<webctrl id='add-all-to-cart' tag='BUTTON' type='submit' />
Removing the title tag does not solve the problem.
The use of wild-cards does not work.
I looked via the "Fuzzy Search":https://docs.uipath.com/studio/docs/fuzzy-search-capabilities
I did the test in Python of the script of the page for the first case: https://www.datacamp.com/community/tutorials/fuzzy-string-python
The result is like in the picture above:
But it's not working too for the first case, since I put the level at 0.1
<html app='chrome.exe' title='"+SelectorString+ "' matching:title='fuzzy' fuzzylevel:title='0.3' /><webctrl id='add-all-to-cart' tag='BUTTON' type='submit' />
with
SelectorString = "Sephora X Coach"
I have no more idea, is the fact that in my first case the button is in a form (when looking at the code of the HTML page) and not in the second case?
Thank you in advance for your help.
I find the solution, I change the selector like that:
<html app='chrome.exe' />
<webctrl id='add[-all]*-to-cart' matching:id='regex' tag='BUTTON' type='submit' />

Changing a time format of an xml file using a bash script

I'm trying to change the formatting of a time in a file using a bash script.
Current time format:
08:05:00
Goal time format:
8-05
There are other timestamps I don't want to change in the file and every instance that I want to change is wrapped in xml:
time="current time format"
Can anyone help?
You must use an XML parser to solve this problem. I would do it in a language that comes with an XML parsing library and a date time parsing library. Python fits the bill
import xml.etree.ElementTree as ET
from datetime import datetime
import sys
tree = ET.parse(sys.argv[1])
# for each element with a "time" attribute, alter the format of the attribute value
for elem in tree.findall('.//*[#time]'):
time = datetime.strptime(elem.get('time'), '%H:%M:%S')
elem.set('time', time.strftime('%k-%M').lstrip())
# print the new XML to stdout
print(bytes.decode(ET.tostring(tree.getroot())))
Testing:
$ cat file.xml
<root>
<a>
<b time="08:05:00">
<c>text contains time 08:05:00</c>
</b>
<d foo="bar" time="19:54:55"/>
</a>
</root>
$ python3 alter_time.py file.xml > new.file.xml
$ cat new.file.xml
<root>
<a>
<b time="8-05">
<c>text contains time 08:05:00</c>
</b>
<d foo="bar" time="19-54" />
</a>
</root>
Error handling left as an exercise

WebDriver Capture Text by XPath

I am attempting to capture a line of text for an automated WebDriver test to use it in a comparison later on. However, I cannot find an XPath that will work with WebDriver. I have used the text() function before to capture text that is not in a tag, but in this instance that is not working. Here is the HTML, note that this text will never be the same, so I cannot use contains or similar functions.
<div id="content" class="center ui-content" data-role="content" role="main">
<div data-iscroll="scroller">
<div class="ui-corner-all ui-controlgroup ui-controlgroup-vertical" data-role="controlgroup">
<a class="ui-btn ui-corner-top ui-btn-hover-c" style="text-align: left" data-role="button" onclick="onDocumentClicked(21228772, "document.php?loan=********&folderseq=0&itemnum=21228772&pageCount=3&imageTypeName=1003 Application - Final&firstInitial=&lastName=")" href="#" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c">
<span class="ui-btn-inner ui-corner-top">
<span class="ui-btn-text">
<img class="checkMark checkMark21228772 notViewedCompletely" width="15" height="15" title="You have not yet viewed this document." src="../images/white_dot.gif"/>
1003 Application - Final. (Jan 11 2012 5:04PM)
</span>
</span>
</a>
In this example, the text I am attempting to capture is: 1003 Application - Final. (Jan 11 2012 5:04PM)
I have inspected the element with Firebug and I have tried the following XPaths with no success.
html/body/div[1]/div[2]/div/div/a[1]/span/span
html/body/div[1]/div[2]/div/div/a[1]/span/span/text()
The WebDriver test is being written in C#.
You can either use this
driver.FindElement(By.XPath(".//div[#id='content']/following-sibling::span[#class='ui-btn-text']")
or
var elem = driver.FindElement(By.Id("Content"));
string text = string.Empty;
if(elem!=null) {
var textElem = elem.FindElement(By.Xpath(".//following-sibling::span[#class='ui-btn-text']"));
if(textElem!=null) text = textElem.Text();
}
I was able to solve this issue by removing the span tags from the XPath.
GetText("html/body/div[3]/div[2]/div/div/a[1]", SelectorType.XPath);
python webdriver code looks something like
driver.find_element_by_xpath("//span[#class='ui-btn-text']").text
But locator may be not uniqe, because I can't see all the code
PS Try to never use locators like html/body/div[1]/div[2]/div/div/a[1]/span/span
Approach:
Find the CSS Selector from the Given DOM
Derived CSS:css=#content div.ui-controlgroup > a[onclick*='onDocumentClicked'] > span > span
Use the C# Library Method to get the Text.

Oracle Clob holds complex XML; how to select specific data with Xquery

I'm trying to extract specific data from a complex XML data set stored in a CLOB field in a commercial app. I cannot change the XML format (namespace, etc), I cannot change the CLOB to XMLType.
The xml data looks like:
<?xml version="1.0" encoding="utf-8"?>
<Calculation>
<ProcessUnitModelScenario Id="1265319" EntityId="10030" EntityName="Chaco Plant" ProcessUnitId="10225" ProcessUnitName="Turbine - Unit 37" EmissionModelId="10000" EmissionModelName="Emissions" ScenarioId="10053" ScenarioName="GHG_Comb_Run_Time" EffectiveDate="1/1/2012 12:00:00 AM" EndDate="2/1/2012 12:00:00 AM" ActiveDate="1/1/2008 12:00:00 AM" ProductionUnitId="10031" ProductionUnitName="Default Production Unit - Month" ProductionScheduleId="13541" OperatingPercentage="100" LinkLevel="1">
<EmissionModel Id="10935" EffectiveDate="1/1/2012 12:00:00 AM" EndDate="2/1/2012 12:00:00 AM">
<EmissionModelMaterial Id="13250" OutputType="Air Emissions" OutputTypeId="1" Media="Vapor" MediaName="Air" MaterialId="83" EquationId="10096" EquationName="GHG Combustion: Run time" EquationUnit="lb/hr" EquationUnitName="lb/hr" EquationBaseUnit="lb/hr" EquationBaseUnitName="lb/hr" SpeciationOption="StandardSpeciation" SpeciationOptionName="Standard Speciation" UseComponentVaporPressureMethods="False" VaporPressureOptionName="Material's vapor pressure methods">
<Material Id="83" Name="Methane" EffectiveId="10082" EffectiveDate="1/1/1990 12:00:00 AM" ComponentBasis="Vapor" MolecularWeight="16.043" LiquidDensity="1.34687732957939" VaporPressureMethod="Riedels" RiedelA="39.205" RiedelB="-1324.4" RiedelC="-3.4366" RiedelD="3.1E-05" RiedelE="2" UseDefinedComposition="False">
<CalculationPeriod StartDate="1/1/2012 12:00:00 AM" EndDate="2/1/2012 12:00:00 AM">
<EquationVariable Id="11079" Name="HeatRating" Order="10" BaseUnit="BTU/sec" EquationUnit="MMBtu/hr" Type="System" TypeName="System Variable" SystemCalculationType="ProcessUnitProperty" SystemCalculationName="Process Unit Property" SystemParameterProcessPropertyId="10005" SystemParameterModelOutputTypeId="1" TimeDependent="False" Value="116" EnteredValue="116" EnteredUnit="MMBtu/hr" />
<EquationVariable Id="11077" Name="GHGEF" Order="20" BaseUnit="lb/BTU" EquationUnit="kg/MMBTU" Type="GlobalEmissionFactor" TypeName="Global Emission Factor" TimeDependent="True" Value="0.001" EnteredValue="0.001" EnteredUnit="kg/MMBTU" />
<EquationVariable Id="11078" Name="RunHrs" Order="30" BaseUnit="hr" Type="Parameter" TypeName="Parameter" ParameterLevel="ProcessUnit" ParameterLevelName="Process Unit" ParameterId="10044" ParameterName="RunHrs - " TimeDependent="True" Value="612" EnteredValue="612" EnteredUnit="hr" />
<EquationVariable Id="11080" Name="kgtolb" Order="40" BaseUnit="lb" Type="GlobalConstant" TypeName="Global Constant" GlobalConstantId="10007" TimeDependent="False" Value="2.20462" />
<EquationVariable Id="11081" Name="OpHrs" Order="45" BaseUnit="hr" EquationUnit="hr" Type="System" TypeName="System Variable" SystemCalculationType="OperatingHours" SystemCalculationName="Operating Hours" TimeDependent="True" Value="744" />
<EquationVariable Id="11082" Name="EmissionRate" Order="46" BaseUnit="lb/hr" Type="FinalResult" TypeName="Final Expression" Formula="(HeatRating*GHGEF)*RunHrs*kgtolb/OpHrs" TimeDependent="True" Value="0.210363418064516" />
<Emission EffectiveDate="1/1/2012 12:00:00 AM" EndDate="2/1/2012 12:00:00 AM" BaseUnit="lb/hr" BaseUnitName="lb/hr" EmissionAmount="0.210363418064516" Unit="lb/hr" UnitName="lb/hr" ResultValue="0.210363418064516" LinkType="Unabated" LinkTypeName="" OperatingHours="744" EmissionMass="156.51038304" EmissionMassUnit="lb" MaterialId="83" EffectiveMaterialId="10082" MaterialName="Methane" MaterialEffectiveDate="1/1/1990 12:00:00 AM" />
</CalculationPeriod>
</Material>
<Material etc...>
</Material>
</EmissionModelMaterial>
<EmissionModelMaterial etc...>
</EmissionModelMaterial>
</EmissionModel>
<EmissionModel etc...>
</EmissionModel>
<ProcessUnitModelScenario etc...>
</ProcessUnitModelScenario>
</Calculation>
My need is to return certain attribute values from the elements for specified combination of [ProcessUnitModelScenario/#ProcessUnitId], [ProcessUnitModelScenario/#ScenarioId], and [Material/#Id].
The XML data is kept in the Air_Calc_Log table Verbose_Xml CLOB field.
In my PL/SQL I am (mis?)using the follow select:
SELECT
XMLType(l.verbose_xml).extract(
'for $scen in /Calculation/ProcessUnitModelScenario
where ($scen/#ScenarioId="10053")
return $scen/* ')
FROM air_calc_log l
WHERE l.vld_site_id = 10030 -- pVldSite
AND l.start_date = To_Date('01/01/2012','mm/dd/yyyy') -- pStartDate
AND l.End_Date = To_Date('04/01/2012','mm/dd/yyyy')
Whatever combination of XQuery/XPath using FLOWR syntax I use I always get the following error message:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token in: 'for $scen in /Calculation/ProcessUnitModelScenario
where ($scen/#ScenarioId="10053")
return $scen/* '
ORA-06512: at "SYS.XMLTYPE", line 111
Can someone help point out what I'm doing wrong?
Try it like this:
SELECT
XMLType(l.verbose_xml).extract(
'/Calculation/ProcessUnitModelScenario[#ScenarioId="10053"]')
FROM air_calc_log l
WHERE l.vld_site_id = 10030 -- pVldSite
AND l.start_date = To_Date('01/01/2012','mm/dd/yyyy') -- pStartDate
AND l.End_Date = To_Date('04/01/2012','mm/dd/yyyy')
Here is a fiddle (Note that I had to change your XML to make it well-formed)

RSS feed not validating because of substr cutting html characters

Currently unable to get my rss feed to validate through W3C RSS Validator. It seems there's a problem with the time/date. If you click the W3C link it'll show the errors. When I comment out the date it works fine but the date is kinda crucial!!
Here's the original script:
include "db.php";
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("cache-control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: text/xml");
print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
?>
<rss version="2.0">
<channel>
<title>MediWales Events</title>
<description>The latest Events, updates and announcements from MediWales.</description>
<link>http://www.mediwales.com</link>
<copyright>Copyright 2011 MediWales.</copyright>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<language>en-us</language>
<lastBuildDate><? print date("D, d M Y H:i:s"); ?> 0000</lastBuildDate>
<managingEditor>info#mediwales.com</managingEditor>
<pubDate><? print date("D, d M Y H:i:s"); ?> 0000</pubDate>
<webMaster>info#mediwales.com</webMaster>
<generator>codeworks rss script (1.0.0)</generator>
<image>
<url>http://mediwales.com/login/uploaded/template/logo.png</url>
<title>MediWales Website</title>
<link>http://www.mediwales.com</link>
<description>The latest Events, updates and announcements from MediWales.</description>
<width>144</width>
<height>52</height>
</image>
<?
$latestnews = mysql_query("SELECT myevents.*, myevents_dates.datefrom from myevents, myevents_dates WHERE myevents_dates.datefrom >= CURDATE() AND myevents.id = myevents_dates.eventid order by myevents_dates.datefrom");
while ($news = mysql_fetch_assoc($latestnews)) {
$datetime = explode(" ",$news[datefrom]);
$date = explode("-",$datetime[0]);
$time = explode(":",$datetime[1]);
$news[description] = strip_tags($news[description]);
$news[description] = htmlspecialchars($news[description]);
echo "<item>";
echo "<title>".mb_convert_encoding(htmlspecialchars($news[title]),"US-ASCII")."</title>";
echo "<description>".mb_convert_encoding(substr($news[description],0, 250),"US-ASCII")."</description>";
echo "<link>http://www.mediwales.com/index.php?id=4&nid=$news[id]</link>";
echo "<pubDate>".date('D, d M Y H:i:s O', mktime($time[0],$time[1],$time[2],$date[1],$date[2],$date[0]))."</pubDate>";
echo "</item>";
}
?>
</channel>
</rss>
Notice that the only error is in the line 56:
nbsp;&</description>
should be:
nbsp;&</description>
The problem is that you are calling htmlspecialchars and then substr, so the last & gets truncated to &, and that makes your feed invalid. Call substr first and htmlspecialchars last, to fix this.
The other things ("Email address is missing real name", "item should contain a guid element") are just recomendations: you should follow them because they are good ideas, but they would caise the feed to fail the validation.
There are a number of other errors you'll need to fix (like cutting off in the middle of an HTML entity). But they provide a Help link for each one.
In specific reference to the date error, if you follow their Help link, you'll see that one of the possible reasons for this warning is that a date is in the future. The date they're complaining about is "Implausible date: Mon, 07 Mar 2011 00:00:00 +0000". Today is 1 Mar 2011, so 7 Mar 2011 is indeed in the future.
If you continue reading their Help link, they explain why this is a problem. The fix is not to include future dates in your feed.
I think they're complaining about the fact that you're using a date that's in the future.
If so, that is not, imho, a reason to declare your feed invalid. Real-world publications often have publication dates in the future.
The spec, which is the actual authority on this doesn't say there's anything wrong with pubdates in the future.
http://cyber.law.harvard.edu/rss/rss.html
Validators can have bugs too. :-)
I've temporarily solved the problem by removing some html characters on my actual website so the feed isn't grabbing them.
I know the problem may arise when we grab the next set of feeds but too rushed to fix at the moment.

Resources