Community discussions

MikroTik App
 
User avatar
sady
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Fri Jul 11, 2008 11:30 am
Location: Russia

creating dude objects by script(sys-id generation problem)

Sun Jan 18, 2009 7:13 pm

I create bash script which must generate 32 graphs from my 32 SNMP maps links. Its output xml code, which i paste in dude. Graphs created well, but without lines in them. When i create that graps in dude, and then export them, the only difference between xml files is IDs. There is scripts, simple output, and diff output:
#!/bin/bash

chart_id=4656286
lines_id=1500
sys_name='\d0\9b\d0\\b8\d0\\bd\d0\\b8\d1\8f \d0\\b4\d0\\b8\d0\\b0\d0\\b3\d1\80\d0\\b0\d0\\bc\d0\\bc\d1\\8b'

X=0
P=1

echo '<?xml version="1.0" ?>
<dude version="3.0rc3">'

#for ((X=0;X<2;X=X+1));do for ((P=0;P<16;P=P+1));do

tx_source_line=`grep -E -B 1 "<sys-name>FC port 0/${P} .*br5k_${X}.*tx" backup-2009.01.16.xml |grep sys-id|cut -d'>' -f2|cut -d'<' -f1`
rx_source_line=`grep -E -B 1 "<sys-name>FC port 0/${P} .*br5k_${X}.*rx" backup-2009.01.16.xml |grep sys-id|cut -d'>' -f2|cut -d'<' -f1`
line1_id=`expr $chart_id + 1`
line2_id=`expr $chart_id + 2`

echo -e " <Chart>
  <sys-type>42</sys-type>
  <sys-id>${chart_id}</sys-id>
  <sys-name>br5k_${X}_port${P}</sys-name>
  <linesID>${lines_id}</linesID>
  <backgroundColor>FFFFFF</backgroundColor>
  <gridColor>C0C0C0</gridColor>
  <font>09000000000000000000000000000000000000000000000100000000417269616C000000000000000000000000000000000000000000000000000000</font>
 </Chart>
 <ChartLine>
  <sys-type>${lines_id}</sys-type>
  <sys-id>${line2_id}</sys-id>
  <sys-name>${sys_name}</sys-name>
  <sourceID>${tx_source_line}</sourceID>
  <lineColor>FF0000</lineColor>
  <fillColor>FF0000</fillColor>
 </ChartLine>
 <ChartLine>
  <sys-type>${lines_id}</sys-type>
  <sys-id>${line1_id}</sys-id>
  <sys-name>${sys_name}</sys-name>
  <sys-nextID>${line2_id}</sys-nextID>
  <sourceID>${rx_source_line}</sourceID>
  <lineColor>0000FF</lineColor>
  <fillColor>0000FF</fillColor>
 </ChartLine>"
lines_id=lines_id+1;
chart_id=chart_id+11;

#done;done
echo  '</dude>'
XML:
 <?xml version="1.0" ?>
<dude version="3.0rc3">
 <Chart>
  <sys-type>42</sys-type>
  <sys-id>4656286</sys-id>
  <sys-name>br5k_0_port1</sys-name>
  <linesID>1500</linesID>
  <backgroundColor>FFFFFF</backgroundColor>
  <gridColor>C0C0C0</gridColor>
  <font>09000000000000000000000000000000000000000000000100000000417269616C000000000000000000000000000000000000000000000000000000</font>
 </Chart>
 <ChartLine>
  <sys-type>1500</sys-type>
  <sys-id>4656288</sys-id>
  <sys-name>\d0\9b\d0\b8\d0\bd\d0\b8\d1\8f \d0\b4\d0\b8\d0\b0\d0\b3\d1\80\d0\b0\d0\bc\d0\bc\d1\8b</sys-name>
  <sourceID>4577150</sourceID>
  <lineColor>FF0000</lineColor>
  <fillColor>FF0000</fillColor>
 </ChartLine>
 <ChartLine>
  <sys-type>1500</sys-type>
  <sys-id>4656287</sys-id>
  <sys-name>\d0\9b\d0\b8\d0\bd\d0\b8\d1\8f \d0\b4\d0\b8\d0\b0\d0\b3\d1\80\d0\b0\d0\bc\d0\bc\d1\8b</sys-name>
  <sys-nextID>4656288</sys-nextID>
  <sourceID>4577156</sourceID>
  <lineColor>0000FF</lineColor>
  <fillColor>0000FF</fillColor>
 </ChartLine>
</dude>
diff output:
 [sady@sady-lin Desktop]$ diff new*
5c5
<   <sys-id>4577861</sys-id>
---
>   <sys-id>4656286</sys-id>
7c7
<   <linesID>1179</linesID>
---
>   <linesID>1500</linesID>
13,14c13,14
<   <sys-type>1179</sys-type>
<   <sys-id>4577870</sys-id>
---
>   <sys-type>1500</sys-type>
>   <sys-id>4656288</sys-id>
21,22c21,22
<   <sys-type>1179</sys-type>
<   <sys-id>4577866</sys-id>
---
>   <sys-type>1500</sys-type>
>   <sys-id>4656287</sys-id>
24c24
<   <sys-nextID>4577870</sys-nextID>
---
>   <sys-nextID>4656288</sys-nextID>
how sys-IDs generated in dude? it is theoretically possible to create object this way?
Please, please, Open Dude Source! Pleaaaaseeeee!!!!!
 
User avatar
sady
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Fri Jul 11, 2008 11:30 am
Location: Russia

Re: creating dude objects by script(sys-id generation problem)

Tue Feb 03, 2009 10:40 pm

i finded that is no problem with my script, this behavior is specific to dude.
situation:
1) we create chart, and add 1 line to it
2) we copy chart to buffer
3) we delete chart
4) we paste from buffer
and no any line in chart!!!! terrible.. or not?
1) rename chart
2) paste from buffer again
miracle! added from buffer chart have all it lines with proper datasources

Now! simple modificate script to generate to text files:
1) with empty charts, with no lines, and fake names (out_dude_pre.txt)
2) with fullfiled charts, with all needed lines, and same IDs as in fake charts (out_dude_fin.txt)
then go to Dude and:
1) open first file (out_dude_pre.txt)
2) select all(Ctrl+A), copy (Ctrl+C)
3) goto Dude chart, paste (Ctrl+V). now you have many empty "fake" charts
4) open second file (out_dude_fin.txt)
5) select all(Ctrl+A), copy (Ctrl+C)
6) goto Dude chart, paste (Ctrl+V). now you have all your charts with needed lines
7) select all fake charts (with Shift key) and delete them

don't forget to:
1) put your latest backup in script workdir, and change @backup-2009.01.16.xml@ to you backup name
2) change variables chart_id and lines_id in script, to values that supposed to be not used
3) change DataSource expression to yours
4) change cicle variable to yours

#!/bin/bash

chart_id=4810006
lines_id=1600
sys_name='\d0\9b\d0\\b8\d0\\bd\d0\\b8\d1\8f \d0\\b4\d0\\b8\d0\\b0\d0\\b3\d1\80\d0\\b0\d0\\bc\d0\\bc\d1\\8b'

X=0
P=0

echo '<?xml version="1.0" ?>
<dude version="3.0rc3">' > out_dude_fin.txt
echo '<?xml version="1.0" ?>
<dude version="3.0rc3">' > out_dude_pre.txt

for ((X=0;X<2;X=X+1));do for ((P=0;P<16;P=P+1));do

tx_source_line=`grep -E -B 1 "<sys-name>FC port 0/${P} .*br5k_${X}.*tx" backup-2009.01.16.xml |grep sys-id|cut -d'>' -f2|cut -d'<' -f1`
rx_source_line=`grep -E -B 1 "<sys-name>FC port 0/${P} .*br5k_${X}.*rx" backup-2009.01.16.xml |grep sys-id|cut -d'>' -f2|cut -d'<' -f1`
line1_id=`expr $chart_id + 3`
line2_id=`expr $line1_id + 3`

echo -e " <Chart>
  <sys-type>42</sys-type>
  <sys-id>${shift_id}${chart_id}</sys-id>
  <sys-name>br5k_${X}_port${P}_pre</sys-name>
  <linesID>${lines_id}</linesID>
  <backgroundColor>FFFFFF</backgroundColor>
  <gridColor>C0C0C0</gridColor>
  <font>09000000000000000000000000000000000000000000000100000000417269616C000000000000000000000000000000000000000000000000000000</font>
 </Chart>" >> out_dude_pre.txt

echo -e " <Chart>
  <sys-type>42</sys-type>
  <sys-id>${shift_id}${chart_id}</sys-id>
  <sys-name>br5k_${X}_port${P}</sys-name>
  <linesID>${lines_id}</linesID>
  <backgroundColor>FFFFFF</backgroundColor>
  <gridColor>C0C0C0</gridColor>
  <font>09000000000000000000000000000000000000000000000100000000417269616C000000000000000000000000000000000000000000000000000000</font>
 </Chart>
 <ChartLine>
  <sys-type>${lines_id}</sys-type>
  <sys-id>${shift_id}${line2_id}</sys-id>
  <sys-name>${sys_name}</sys-name>
  <sourceID>${rx_source_line}</sourceID>
  <lineColor>FF0000</lineColor>
  <fillColor>FF0000</fillColor>
 </ChartLine>
 <ChartLine>
  <sys-type>${lines_id}</sys-type>
  <sys-id>${shift_id}${line1_id}</sys-id>
  <sys-name>${sys_name}</sys-name>
  <sys-nextID>${shift_id}${line2_id}</sys-nextID>
  <sourceID>${tx_source_line}</sourceID>
  <lineColor>0000FF</lineColor>
  <fillColor>0000FF</fillColor>
 </ChartLine>" >> out_dude_fin.txt
lines_id=`expr $lines_id + 1`
chart_id=`expr $chart_id + 9`

done;done
echo  '</dude>'>> out_dude_fin.txt
echo  '</dude>'>> out_dude_pre.txt
unix2dos out_*

NOW YOU CAN AUTOMATE CREATION OF SIMILLAR OBJECTS! HAVE FUN!
Please, please, Open Dude Source! Pleaaaaseeeee!!!!!

Who is online

Users browsing this forum: No registered users and 19 guests