Wget certain graph images from Cacti

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

Wget certain graph images from Cacti

Post by ^rooker »

WARNING: This HowTo ain't done, yet. I'm using it for collecting URLs and dropping notes until I've figured out how.

Cacti's automatic graph export functionality is nice, but I'm having some problems with it on Debian Squeeze:
Jun 17 11:48:01 host1 /USR/SBIN/CRON[28671]: (www-data) CMD (php /usr/share/cacti/site/poller.php >/dev/null 2>/var/log/cacti/poller-error.log)
Jun 17 11:48:25 host1 suhosin[28675]: ALERT - script tried to disable memory_limit by setting it to a negative value -1 bytes which is not allowed (attacker 'REMOTE_ADDR not set', file 'unknown')
Jun 17 11:48:25 host1 suhosin[28672]: ALERT - script tried to disable memory_limit by setting it to a negative value -1 bytes which is not allowed (attacker 'REMOTE_ADDR not set', file 'unknown')
I also want different representations downloaded in different intervals, so I thought I'd check if I'm able to manually fetch the graph images using "wget".

1) The session-handling of Cacti does not like wget:
I tried in different variations, and some forum entries said it's possible, but I didn't find an example of syntax that actually allowed me to download a dump of the "graph preview" page, where the graph images were actually there (and not the login).

So, we'll change to "Web Basic Authentication". The following steps are for Apache2:

2) Create htpasswd/htgroup files for Cacti users:
On Debian systems, you will find Cacti's config in "/etc/cacti".
There you put 2 files: htpasswd (for usernames+passwords) and htgroup (for group assignment).

First, create a htpasswd file for your user:

Code: Select all

htpasswd -m -c /etc/cacti/htpasswd <username>
Now, create a file called "/etc/cacti/htgroup" and add the following line to it:

Code: Select all

cacti: <username>
3) Tell Apache to enable Web Basic authentication for Cacti:
On Debian systems, the Apache settings for Cacti are automatically installed in "/etc/apache2/conf.d/cacti.conf", which is actually a symlink:
/etc/apache2/conf.d/cacti.conf -> ../../cacti/apache.conf
Edit that file and add the following lines in the "<Directory>" block:

Code: Select all

# Web Basic Authentication for Cacti (instead of built-in):
    AuthType Basic
    AuthName "Haus-Sensoren"
    AuthUserFile /etc/cacti/htpasswd
    AuthGroupFile /etc/cacti/htgroup
    Require group cacti
Then reload Apache's configuration:

Code: Select all

/etc/init.d/apache2 reload
4) Allow your users in Cacti to logon using "Web Basic" as method:
Logon to Cacti (as admin), go to the "Console" and open the following page:
Utilities > User Management
Now open each user and switch the authentication method to "Web Basic".

5) Change Cacti to "Web Basic" authentication:
Open the following page in Cacti's Console:
Configuration > Settings > Authentication
Now, change the logon method to "Web Basic".

6) Logging onto, and downloading the graphs using wget:
Now, that authentication has been changed to "Web Basic", we can use wget's built-in parameters "--user" and "--password", like this:

Code: Select all

$ wget --restrict-file-names=windows --user='<username>' --password='<password>' -l 1 -r -P /folder/where_to_put/the_graphs http://status.myserver.com/cacti/graph_view.php?action=preview

References:
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply