Community discussions

MikroTik App
 
Pablete
just joined
Topic Author
Posts: 22
Joined: Wed May 23, 2007 4:11 pm

Exporting Dude's HTTP graphs and charts with cURL

Mon Jul 18, 2011 3:34 pm

Hi

I got an automatic export of any dude graph with cURL.
The way I have got to do it is running a script each five minutes, as a Windows scheduled task.
The windows script is like this
@echo off
"c:\Program files\curl\curl" -s -d process=login -d page=start -d user=JohnSmith -d password=Pocahontas -c cookiecurl.tmp "http://dudeserver.myenterprise.com:81/dude/main.html" > dude2web.log
rem
rem
echo          Servers >> dude2web.log
copy "C:\Program Files\Dude\data\files\Servers.png" C:\wamp\www\dude\servers.png >> dude2web.log
"c:\Program files\curl\curl" -b cookiecurl.tmp -o C:\wamp\www\dude\server1cpu.png "http://dudeserver.myenterprise.com:81/dude/chart.png?page=chart_picture&download=yes&id=248168&type=0&num=1" >> dude2web.log
"c:\Program files\curl\curl" -b cookiecurl.tmp -o C:\wamp\www\dude\server2disk.png "http://dudeserver.myenterprise.com:81/dude/chart.png?page=chart_picture&download=yes&id=225764&type=0&num=1" >> dude2web.log
rem
rem
echo          Network >> dude2web.log
copy "C:\Program Files\Dude\data\files\Network.png" C:\wamp\www\dude\network.png >> dude2web.log
"c:\Program files\curl\curl" -b cookiecurl.tmp -o C:\wamp\www\dude\routertraffic.png   "http://dudeserver.myenterprise.com:81/dude/chart.png?page=chart_picture&download=yes&id=2956126&type=2&num=0" >> dude2web.log
"c:\Program files\curl\curl" -b cookiecurl.tmp -o C:\wamp\www\dude\packetloss.png "http://dudeserver.myenterprise.com:81/dude/chart.png?page=chart_picture&download=yes&id=6736008&type=0&num=1" >> dude2web.log
...
"c:\Program files\curl\curl" -s -b cookiecurl.tmp "http://dudeserver.myenterprise.com:81/dude/login.html?drop_cookie=true" >> dude2web.log
A brief explanation

In this example, my dude server is http://dudeserver.myenterprise.com:81 , therefore the dude web service is running in the port 81.

Note that every cURL invocation is one single line from "c:\Program files\curl\curl... to >> dude2web.log". If you see it split in two lines is due to the forum engine or your web browser.

The first cURL invocation is not a HTTP GET, but a post. In the post I say to the dude's web server the following data:
- process=login
- page=start
- user=JohnSmith
- password=Pocahontas
Please change the user and the password to any that can navigate in the web interface of your Dude server.
The first cURL invocation gets a cookie from the dude's web server and stores it to a file named cookiecurl.tmp (option -d)

The echo is because I want a log. You can remove this line.

The copy line is to copy a network map from the dude folder to my web server folder. I have configured dude to export the map each 5 minutes through the export tab. It creates a png file. But you're not reading this post for the automatic export, do you? :)

The subsequent cURL invocations, for instance
"c:\Program files\curl\curl" -b cookiecurl.tmp -o C:\wamp\www\dude\server1cpu.png "http://dudeserver.myenterprise.com:81/d ... pe=0&num=1" >> dude2web.log
- makes the call with the cookie stored in cookiecurl.tmp (option -b)
- retrieves the data -whatever it is- and stores it in a file like C:\wamp\www\dude\server1cpu.png (option -o)
- the data retrieved is specified in the url.
- after the url there is a >> dude2web.log that writes to a log. Yes if you don't want logs you can remove this part also.

The last cURL invocation is the http session logout for the cURL client. If the logout is not performed, then, later, you will NOT get new images but the same ones, except if you make the next image retrieval when the session timeout is expired (Settings -> Server tab -> Web Access parameters -> Session Timeout, the default is 00:15:00)

How do I know which are the urls:
1 Open the browser and log on to the dude server.
2 Browse and locate the image to export
3 Depending on your browser:
In Microsoft Internet Explorer, right click in the image and select properties. There is the url
In Mozilla Firefox, right click in the image and select "Copy the image path". Now you have the url in the clipboard.
4 remember to put it between quotes "

DISCLAIMER
This is working for me. It will possibly work for you also, but it depends on two softwares that aren't under my control (cURL and The Dude itself), so I can't assure it will work (at least, eternally).
The url for each image seems not to change as long as the object does not changes. But it can change tomorrow, due to the Dude behaviour or because you have done changes in the Dude configuration. It should be a Dude engineer the one that states or claims that the link to a graph is permanent.
Simpy, I have it working at my work during one week, and it looks like it works. That's all.

Regards.
POST EDIT: This is running flawlessly since I wrote it three months ago, and I'm really happy with this solution.
Last edited by Pablete on Sun Oct 02, 2011 10:49 am, edited 9 times in total.
 
Pablete
just joined
Topic Author
Posts: 22
Joined: Wed May 23, 2007 4:11 pm

Re: Exporting Dude graphs with cURL

Wed Jul 27, 2011 3:33 pm

Hi

I had the issue described in this post.
I have reduced the frequency, now I read the graphs each hour and the issue has disapeared.

Apart from this, everything works.

Regards

-----
Post edit: I have solved the issue of the second post by adding a logout in the script. Now I get the graphs again each 5 min without refresh problems.
I have updated the first post.
Regards
Last edited by Pablete on Thu Sep 08, 2011 12:00 pm, edited 1 time in total.
 
User avatar
geoffsmith31
Member Candidate
Member Candidate
Posts: 155
Joined: Fri Nov 05, 2010 6:08 am
Location: Toowoomba, Australia

Re: Exporting Dude graphs with cURL

Thu Jul 28, 2011 11:26 am

Thanks for sharing your work. I have a need to do something similar for a monthly management report and have been doing it with other systems etc and not really getting what I want. I will have a play with this if/when I get time.
 
Pablete
just joined
Topic Author
Posts: 22
Joined: Wed May 23, 2007 4:11 pm

Re: Exporting Dude graphs with cURL

Thu Sep 08, 2011 11:55 am

Hi

I have solved the issue of the second post by adding a logout in the script.
Now I get the graphs again each 5 min without refresh problems.

Regards
 
arisanto
just joined
Posts: 1
Joined: Fri Aug 31, 2018 7:12 am

Re: Exporting Dude's HTTP graphs and charts with cURL

Fri Aug 31, 2018 7:47 am

Can we export MAP image with CURL.

I Do bellow code but it keep crashing..

@echo off
"c:\xampp\curl" -s -d process=login -d page=start -d user=thedude -d password=hbohbo -c cookiecurl.tmp "http://localhost:82/dude/main.html" > dude2web.log
rem
rem
echo Servers >> dude2web.log

"c:\xampp\curl" -s -d process=login -d page=start -d user=thedude -d password=hbohbo -c cookiecurl.tmp "http://localhost:82/dude/main.html" > dude2web.log
"d:\xampp\curl" -b cookiecurl.tmp -o d:\xampp\htdocs\backup\charts\peta\server1cpu.png "http://localhost:82/dude/Trafik.png?pag ... &id=184895" >> dude2web.log

rem
rem



Thnx.
 
tssthrowaway
just joined
Posts: 2
Joined: Sun Nov 11, 2018 4:28 am

Re: Exporting Dude's HTTP graphs and charts with cURL

Sun Nov 11, 2018 7:15 am

Does anyone have some code similar to this that works with The Dude v6 - it seems the web side is very different in the new builds.
 
foraster
just joined
Posts: 23
Joined: Tue Oct 01, 2019 5:31 pm

Re: Exporting Dude's HTTP graphs and charts with cURL

Fri Oct 28, 2022 1:49 pm

Same question here, does the Dude v6+ have a map export function other than viewing the maps on webfig?

Who is online

Users browsing this forum: No registered users and 3 guests