1

I was looking for a way to automatically download the weathermap image from the Cacti Weathermap plugin at regular intervals. There does not seem to be an easy way to do this listed anywhere on the internet using only Windows, so I thought I'd a) ask here and b) post what I've managed so far.

P.S. I've posted where I got up to in one of the answers below.

Gostega
  • 429
  • 1
  • 5
  • 14

1 Answers1

3
  1. You can easily right click - Save As while on the weathermap page. This produces a file called weathermap-cacti-plugin.png.
  2. No such file is available from the webpage however. Right clicking - view URL gave me this: http://<mydomain>/plugins/weathermap/weathermap-cacti-plugin.php?action=viewimage&id=df9c40dcab42d1fd6867&time=1448863933
  3. I did a quick check in powershell to see if this was downloadable (it was):

    $client = new-object System.Net.WebClient
    $client.DownloadFile("http://<mydomain>/plugins/weathermap/weathermap-cacti-plugin.php?action=viewimage&id=df9c40dcab42d1fd6867&time=1448864049", "C:\data\test.png")
    
  4. Following a hunch, I refreshed the page and copied a couple more URLs:

    <mydomain>/plugins/weathermap/weathermap-cacti-plugin.php?action=viewimage&id=df9c40dcab42d1fd6867&time=1448863989
    <mydomain>/plugins/weathermap/weathermap-cacti-plugin.php?action=viewimage&id=df9c40dcab42d1fd6867&time=1448864049 
    

    As I had suspected, the time= changed every time I refreshed the page.

  5. Following another hunch, I checked the changing digits (1448863989 etc) on epochconverter.com and got a valid system time which matched my own.

  6. I found a powershell command (Keith Hill's answer on this question) to get the current Unix time

    [int64](([datetime]::UtcNow)-(get-date "1/1/1970")).TotalSeconds
    

    and added this into the powershell download script

    $client = new-object System.Net.WebClient
    $time=[int64](([datetime]::UtcNow)-(get-date "1/1/1970")).TotalSeconds
    $client.DownloadFile("http://<mydomain>/plugins/weathermap/weathermap-cacti-plugin.php?action=viewimage&id=df9c40dcab42d1fd6867&time=$time", "C:\data\test.png")
    

This seems to work - the file test.png modified timestamp was updated every time I ran the code, and it opened showing a valid picture of the weathermap. All that's required now is to put this in a proper script and schedule it to run every X minutes and save to a folder. I am sure scheduling powershell scripts in Task Scheduler is covered elsewhere so I will not repeat it here.

If anyone knows an easier way of doing this, please let me know. Otherwise, vote up my answer - I have searched a lot and cannot find any other results on the net that let you do this using only Windows. The Cacti forums have a couple of solutions, but they require you to do stuff on the Linux server which is hard for a Linux noob like me.

Gostega
  • 429
  • 1
  • 5
  • 14
  • 1
    (author of Weathermap) The timestamp was only added there to try and stop the browser from caching. It's not significant to anything internal to weathermap. I'm pretty sure it doesn't even get read, so you can put any random string, or nothing at all there, also. – AnotherHowie Mar 02 '16 at 09:16
  • Oh my. Thanks for this tip. I feel significantly less clever. But it certainly makes it easier - I confirmed working using this URL: ?action=viewimage&id=df9c40dcab42d1fd6867&time=onedoesnotsimplydownloadweathermap and it worked. – Gostega Mar 09 '16 at 06:21