Smarty array with null value - smarty

I'm trying to get the value of one position of array in a smarty .tpl, here's my code
{$destination = $destination_id}
{$bid = $destination}
{$shippingRate = $shipping.rates.$bid|#json_encode}
$dest: {$destination}
<br>
$bid: {$bid}
<br>
$shippingRate: {$shippingRate}
HTML result:
$dest: 244
$bid: 244
$shippingRate: null
And this is an example with the var $bid hardcoded:
{$destination = $destination_id}
{$bid = 244}
{$shippingRate = $shipping.rates.$bid|#json_encode}
$dest: {$destination}
<br>
$bid: {$bid}
<br>
$shippingRate: {$shippingRate}
HTML result:
$dest: 244
$bid: 244
$shippingRate: {"destination_id":"244","status":"A"}
I guess that I'm doing something wrong in the assignation of $bid, I did try with the following options with the same result:
{$bid = $destination|intval}
{$bid = $destination|strip|intval}
{$bid = $destination|strip}

Related

Telegraf unable to pull route table information from Arista MIB

So I'm trying to collect routing stats from some Aristas.
When I run snmpwalk it all seems to work...
snmpwalk -v2c -c pub router.host ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType
ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType.ipv4.other = Gauge32: 3
ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType.ipv4.connected = Gauge32: 8
ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType.ipv4.static = Gauge32: 26
ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType.ipv4.ospf = Gauge32: 542
ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType.ipv4.bgp = Gauge32: 1623
ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType.ipv4.attached = Gauge32: 12
ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType.ipv4.internal = Gauge32: 25
ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType.ipv6.other = Gauge32: 3
ARISTA-FIB-STATS-MIB::aristaFIBStatsTotalRoutesForRouteType.ipv6.internal = Gauge32: 1
But when I try to pull the stats with telegraf I get different information with missing context...
BGP,agent_host=10.45.100.20,host=nw01.ny5,hostname=CR.NY aristaFIBStatsTotalRoutesForRouteType=2i 1654976575000000000
BGP,agent_host=10.45.100.20,host=nw01.ny5,hostname=CR.NY aristaFIBStatsTotalRoutes=2260i 1654976575000000000
BGP,agent_host=10.45.100.20,host=nw01.ny5,hostname=CR.NY aristaFIBStatsTotalRoutesForRouteType=8i 1654976575000000000
BGP,agent_host=10.45.100.20,host=nw01.ny5,hostname=CR.NY aristaFIBStatsTotalRoutesForRouteType=63i 1654976575000000000
According to the MIB documentation..
https://www.arista.com/assets/data/docs/MIBS/ARISTA-FIB-STATS-MIB.txt
it is using IANA-RTPROTO-MIB.txt protocol definitions but I have no idea where to derive that information from as the retrieved data via telegraf isn't showing me anything. Anyone know how to deal with this?
First, you might want to enable telegraf to return the index of the returned rows by setting index_as_tag = true inside the inputs.snmp.table.
Then, add the following processors in your config:
# Parse aristaFIBStatsAF and aristaFIBStatsRouteType from index for BGP table
[[processors.regex]]
namepass = ["BGP"]
order = 1
[[processors.regex.tags]]
## Tag to change
key = "index"
## Regular expression to match on a tag value
pattern = "^(\\d+)\\.(\\d+)$"
replacement = "${1}"
## Tag to store the result
result_key = "aristaFIBStatsAF"
[[processors.regex.tags]]
## Tag to change
key = "index"
## Regular expression to match on a tag value
pattern = "^(\\d+)\\.(\\d+)$"
replacement = "${2}"
## Tag to store the result
result_key = "aristaFIBStatsRouteType"
# Rename index to aristaFIBStatsAF for BGP table with single index row
[[processors.rename]]
namepass = ["BGP"]
order = 2
[[processors.rename.replace]]
tag = "index"
dest = "aristaFIBStatsAF"
[processors.rename.tagdrop]
aristaFIBStatsAF = ["*"]
# Translate tag values for BGP table
[[processors.enum]]
namepass = ["BGP"]
order = 3
tagexclude = ["index"]
[[processors.enum.mapping]]
## Name of the tag to map
tag = "aristaFIBStatsAF"
## Table of mappings
[processors.enum.mapping.value_mappings]
0 = "unknown"
1 = "ipv4"
2 = "ipv6"
[[processors.enum.mapping]]
## Name of the tag to map
tag = "aristaFIBStatsRouteType"
## Table of mappings
[processors.enum.mapping.value_mappings]
1 = "other"
2 = "connected"
3 = "static"
8 = "rip"
9 = "isIs"
13 = "ospf"
14 = "bgp"
200 = "ospfv3"
201 = "staticNonPersistent"
202 = "staticNexthopGroup"
203 = "attached"
204 = "vcs"
205 = "internal"
Disclaimer: did not test this in telegraf, so there might be some typo's

Typoscript image change every 15 days

I would like to make a change of image say every 15 days. Or twice a month. When the date is between the 1 and 15 is an image, and if it is from 16 to 30 another, so on, are 24 images in the year. I would like it to be the typoscript that manages the change of the image.
I took the following typosript:
lib.headerlogo1 = COA
lib.headerlogo1 {
10 = LOAD_REGISTER
10 {
divSem.cObject = TEXT
divSem.cObject {
data = date:U
strftime = %U
current = 1
setCurrent.data = date:U
setCurrent.wrap = |/2
prioriCalc = 1
}
}
20 = FILES
20 {
references {
data = levelmedia: -1, slide
}
renderObj = IMAGE
renderObj {
file.import.dataWrap = {file:current:storage}:{file:current:identifier}
#file.import.listNum = 0
altText.data = file:current:title
# Affiche bien la valeur de : divSem
#stdWrap.insertData = 1
#stdWrap.wrap = <div class="banner{register:divSem}">|</div>
}
# insertData = 1
insertData = 1
# IT'S FAILLED !!
begin = {register:divSem}
maxItems = 1
}
30 = TEXT
30 {
stdWrap.insertData = 1
stdWrap.wrap = <div class="{register:divSem}">|</div>
}
}
The problem is that I can not start the value of the registry begin = {register:divSem} ... It always starts at 0! Do you have an idea ? The display of the registers in 30 = TEXT is correct.
Do you have a good idea to modify the typoscript?
I just found the solution, instead of begin = {register: divSem}, I did this:
begin.cObject = TEXT
begin.cObject {
value = 0
value.override.cObject = CASE
value.override.cObject {
key.data = register:divSem
1 = TEXT
1.value = 1
2 = TEXT
2.value = 2
...
24 = TEXT
24.value = 24
default = TEXT
default.value = 2
}
}
Maybe there is more simple, if you have an idea, I'm interested.
Best regards.
You found the important detail: you need a .cObject to fill in any data in the simple property.
Why so complicated with a CASE that outputs the same as the key?
So the simplest way would be:
begin.cObject = TEXT
begin.cObject.data = register:divSem
maybe this also worked like you do in .30:
begin = {register:divSem}
begin.insertData = 1
and a more direct way of your .30:
instead of an .insertData for a .wrap use .dataWrap
begin.stdWrap.dataWrap = {register:divSem}
:
30 = TEXT
30.dataWrap = <div class="{register:divSem}">|</div>

Classic ASP - Pull URL from String

Trying to only pull the URL between two quotes in a text string. I want to end with "www.youtube.com/embed/abcdefg" Currently, EndURL pulls a 0 which means it didn't find a double quote.
Link_Youtube = <iframe width="560" height="315" src="//www.youtube.com/embed/abcdefg" frameborder="0" allowfullscreen></iframe>
StartURL = Instr(Link_Youtube,"src=")
EndURL = Instr(startURL+7, Link_Youtube, Instr(Link_Youtube,""""))
Link_Youtube = Mid(Link_Youtube, startURL+6, EndURL)
Updated (working) Code:
If Instr(Link_Youtube,"iframe") > 0 Then 'embed
startURL = Instr(Link_Youtube,"src=")+7
EndURL = Instr(startURL, Link_Youtube, """") - startURL
Link_Youtube = Mid(Link_Youtube, startURL, EndURL)
End If

How to scrape all the image url and alt tag within it using scrapy

My target is to crawl image url and image alt tag using scrapy . I tried many combinations but still didn't achieve it.
Here is what i tried
def parse_item(self, response):
sel = Selector(response)
item = imageItem()
item['crawl_time'] = time.asctime( time.localtime(time.time()))
item['crawl_date'] = time.asctime( time.localtime(time.strftime("%Y%m%d")))
item['url'] = response.url
for img in hxs.select('//img'):
item['title'] = node.xpath("#alt").extract()
item['iurl'] = node.xpath("#src").extract()
if response.meta['depth'] == 1:
exit
return item
Some issues there:
You already have sel selector. But you use hxs in the loop
in the loop, you are using node instead of img
does it make more sense that each loop should yield one image item
This is my tested and working code:
def parse_item(self, response):
sel = Selector(response)
images = sel.xpath('//img')
for img in images:
item = imageItem()
item['url'] = response.url
title = img.xpath('./#alt').extract() or ''
item_title = title[0] if title else ''
item['title'] = item_title
iurl = img.xpath('./#src').extract() or ''
item_iurl = iurl[0] if iurl else ''
item['iurl'] = item_iurl
yield item
Here is the below code using which I achieved the result , but depth is still 1
class MySpider(CrawlSpider):
name = 'imageaggr'
start_urls = ['http://www.dmoz.org/','http://timesofindia.indiatimes.com/','http://www.nytimes.com','http://www.washingtonpost.com/','http://www.jpost.com','http://www.rediff.com/']
rules = (
# Extract links matching 'category.php' (but not matching 'subsection.php')
# and follow links from them (since no callback means follow=True by default).
Rule(SgmlLinkExtractor(allow=('', ), deny=('defghi\.txt')), callback='parse_item'),
# Extract links matching 'item.php' and parse them with the spider's method parse_item
# Rule(SgmlLinkExtractor(allow=('\.cms','\.html' )), deny=('parse_item\.html'))),
#Rule(SgmlLinkExtractor(allow=('news', )), callback='parse_item'),
)
def parse_item(self, response):
sel = Selector(response)
images = sel.xpath('//img')
image_count = len(images)
count = 0
while(count < image_count):
item = imageItem()
item['url'] = response.url
title = sel.xpath('//img/#alt').extract()[count] or ''
if title == '':
break
item['title'] = title
iurl = sel.xpath('//img/#src').extract()[count] or ''
item['iurl'] = iurl
item['crawl_time'] = time.asctime( time.localtime(time.time()))
crawl_date = time.strftime("%Y%m%d")
item['crawl_date'] = crawl_date
count = count + 1
return item

php undefined variables error when displaying pdf with mpdf

i have been in crisis for over 2 days with this pdf thing.Its not showing any error in the resulting action page,still not displaying in pdf document.Can anyone plz sort this this out, maybe a simple one i guess not sure.The code is below.
Anyways thanks in advance,all.
<?php
if(isset($_POST['email'])){
$email = $_POST['email'];
$fileno = $_POST['fileno'];
$header = $_POST['header'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$stime = $_POST['stime'];
$venue = $_POST['venue'];
$meettype = $_POST['meettype'];
$Itchair = $_POST['Itchair'];
$mem_pres = $_POST['mem_pres'];
$invite = $_POST['invite'];
$head = $_POST['head'];
$slno = $_POST['slno'];
$subject = $_POST['subject'];
$decision = $_POST['decision'];
$incharge = $_POST['incharge'];
$date = $_POST['date'];
$remarks = $_POST['remarks'];
}
include("MPDF54/mpdf.php");
$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0;
$mpdf->WriteHTML(file_get_contents("http://localhost/Bescom/besc_latest.php?email=$email&fileno=$fileno&header=$header&day=$day&month=$month&year=$year&stime=$stime&venue=$venue&meettype=$meettype&Itchair=$Itchair&mem_pres=$mem_pres&invite=$invite&head=$head&slno=$slno&subject=$subject&decision=$decision&date=$date&incharge=$incharge&remarks=$remarks"));
$mpdf->Output();
?>
Add following at top of mpdf.php
error_reporting(0);
This will resolved the issue.

Resources