Ad Widget

Collapse

autentication graph

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alefilly
    Junior Member
    • May 2009
    • 6

    #1

    autentication graph

    hi all,
    i wanto to download (from wget or other) a zabbix graph image.
    i can't do this because is necessary logon.
    how can i bypass this?

    i try http://userass@url, and also http://url?user=user&pass=pass but not work
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #2
    You need to give the guest user read permission to the graph. The guest user is normally part of the guests group. Give the guests group read only permission to the host for which the graph is part of. Also the guest user must not have a password.

    There may be another way if you're willing to do some digging. Look at how the authentication code works and see what kind of information is stored by the browser after login. You would then need to write your script to be smart enough to login using wget and then storing some of the local parameter information. I'll see if I can look into it later to devise a way to do this more easily.

    Hopefully with the API in the future logins may become much easier for things like this.
    RHCE, author of zbxapi
    Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
    Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

    Comment

    • alefilly
      Junior Member
      • May 2009
      • 6

      #3
      thanks...

      i have try also with wget cookie --load-cookies=, but i can not export cookie both from firefox and IE.

      with http://zabbixurl/index.php?login=1&f...XX&enter=ENTER i enter in zabbix, but this is not valid url for the graph page

      Comment

      • nelsonab
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Sep 2006
        • 1233

        #4
        Here's a little bash script I hacked together.

        You will need to set the zbx_host variable appropriately for your setup.

        Code:
        #!/bin/bash
        
        # get_chart.sh user password chartid
        # 5-29-2009
        # This script expects three arguments, the first is the zabbix login
        # the second is the password and the third is the numeric chart id
        #
        # **** WARNING!!!! ****
        # THIS SCRIPT DOES NOT DO ANY ERROR CHECKING! DO NOT USE BLINDLY
        # Also there is no simple way to check the validity of a graph id or weather
        # the results were successful as Zabbix will always return a JPEG image
        #
        # How it works:
        # First we need to log into the zabbix system and receive a session id
        # cookie.  Then when we have the cookie we can then retrieve the graph.
        # The cookie file is deleted after every execution and requested anew
        # to prevent stale cookies.
        
        zbx_host=""
        width=829
        
        result=$(wget --save-cookies=cookies.txt --keep-session-cookies --post-data "name=$1&password=$2&enter=Enter" -O - -q $zbx_host/index.php?login=1 | grep window.location)
        
        if [ "$result" ]
        then
          echo "Authenticated successfully, getting graph"
          wget --load-cookies=cookies.txt -O chart.jpg -q "$zbx_host/chart2.php?graphid=$3&width=$width"
        fi
        
        rm cookies.txt
        After execution you will then have a file called chart.jpg which is the resulting graph. If the file does not exist there was a problem with authentication. This should give you the basic foundation for building your own more complex script. If you need help with writing that let me know.
        Last edited by nelsonab; 10-10-2012, 16:45. Reason: email
        RHCE, author of zbxapi
        Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
        Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

        Comment

        • alefilly
          Junior Member
          • May 2009
          • 6

          #5
          very very great!

          wget in my machine return error in (--keep-session-cookies) but it is ok also if i delete it.

          Comment

          • alefilly
            Junior Member
            • May 2009
            • 6

            #6
            grrrrr

            is not the true...
            without --keep-session-cookies download an image with write "ERROR: no permission!"

            Comment

            • nelsonab
              Senior Member
              Zabbix Certified SpecialistZabbix Certified Professional
              • Sep 2006
              • 1233

              #7
              Yep, the first wget statement is for getting the zbx_sessionid cookie. I did my work on OpenSuSE 10.3 and wget-1.10.2-78.
              RHCE, author of zbxapi
              Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
              Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

              Comment

              • alefilly
                Junior Member
                • May 2009
                • 6

                #8
                my version is GNU Wget 1.9+cvs-stable (Red Hat modified)

                Comment

                • jobench
                  Junior Member
                  • May 2010
                  • 1

                  #9
                  Send 'Bar reports' send with perl script

                  Thanks a lot, works perfect for me (Ubuntu / CentOS )

                  I hacked together a little perl script (can be placed into a crontab), which does the following:

                  1. %image_sources contains a hash which can be extended, with the zabbix report url, the title (for the html mail)..
                  2. the function getImages(), first connects (through http-authentification) to get the cookie and saves the 4 report graphs into a temopary directory (/tmp/[date_today]) and finally sends (rsync) the images to a webserver with public access (so the images can be retieved from a email account without being logged into zabbix)
                  3. the function sendMail uses 'unix sendmail' to send an html mail with these public links

                  Hope this can help someone

                  Code:
                  #!/usr/bin/perl
                  use POSIX qw(setsid strftime);
                  
                  my $year = strftime "%Y", localtime;
                  my $now  = strftime "%s", localtime;
                  my $time_frame_till  = $now;
                  my $time_frame_since = $now - 604800;
                  
                  my $today                = strftime "%a, %d/%m/%Y %Hh", localtime;
                  my $dirname_images_short = strftime "%Y-%m-%d_%H%M%S",    localtime;
                  my $zbx_host             = "http://zabbix.yourdomain.com/zabbix";
                  my $zbx_public           = "http://zabbix.yourdomain.com/public";
                  
                  my $title   = 'YOURDOMAIN - traffic status report';
                  my $to      = '[email protected]';
                  my $from    = '[email protected]';
                  my $subject = "Zabbix report - $today";
                  
                  my %image_sources = (
                  	'tomcat_errors.png' => {
                  		'title' => 'Tomcat errors: 404 / 500',
                  		'url' =>
                  		  "$zbx_host/chart_bar.php?config=1&title=Tomcat+status&xlabel=&ylabel=&scaletype=2&showlegend=1&report_timesince=$time_frame_since&report_timetill=$time_frame_till&items[1][caption]=404&items[1][itemid]=28387&items[1][color]=EE0000&items[1][calc_fnc]=2&items[1][axisside]=0&items[2][caption]=500&items[2][itemid]=28388&items[2][color]=0000EE&items[2][calc_fnc]=2&items[2][axisside]=0",
                  	},
                  	'apache_errors.png' => {
                  		'title' => 'Apache errors: 404 / 500',
                  		'url' =>
                  		  "$zbx_host/chart_bar.php?config=1&title=Apache+status&xlabel=&ylabel=&scaletype=2&showlegend=1&report_timesince=$time_frame_since&report_timetill=$time_frame_till&items[1][caption]=404&items[1][itemid]=28398&items[1][color]=EE0000&items[1][calc_fnc]=2&items[1][axisside]=0&items[2][caption]=500&items[2][itemid]=28400&items[2][color]=0000EE&items[2][calc_fnc]=2&items[2][axisside]=0",
                  	},
                  	'apache_traffic.png' => {
                  		'title' => 'Apache traffic',
                  		'url' =>
                  		  "$zbx_host/chart_bar.php?config=1&title=Apache+traffic&xlabel=&ylabel=&scaletype=2&showlegend=1&report_timesince=$time_frame_since&report_timetill=$time_frame_till&items[1][caption]=ALL&items[1][itemid]=28402&items[1][color]=00CC00&items[1][calc_fnc]=2&items[1][axisside]=0&items[2][caption]=Google&items[2][itemid]=28385&items[2][color]=00EEEE&items[2][calc_fnc]=2&items[2][axisside]=0",
                  	},
                  	'tomcat_response_times.png' => {
                  		'title' => 'Tomcat response times',
                  		'url' =>
                  		  "$zbx_host/chart_bar.php?config=1&title=Tomcat+RTimes&xlabel=&ylabel=&scaletype=2&showlegend=1&report_timesince=$time_frame_since&report_timetill=$time_frame_till&items[1][caption]=MASS+All&items[1][itemid]=28318&items[1][color]=0000AA&items[1][calc_fnc]=2&items[1][axisside]=0&items[2][caption]=MRES+All&items[2][itemid]=28310&items[2][color]=6666FF&items[2][calc_fnc]=2&items[2][axisside]=0&items[3][caption]=MASS+Listview&items[3][itemid]=28334&items[3][color]=BB00BB&items[3][calc_fnc]=2&items[3][axisside]=0&items[4][caption]=MASS+Overview&items[4][itemid]=28330&items[4][color]=FF66FF&items[4][calc_fnc]=2&items[4][axisside]=0"
                  	},
                  );
                  
                  sub getImages() {
                  	my $tmp_dir  = '/tmp/' . $dirname_images_short;
                  	my $tmp_file = '/tmp/zabbix_cookie_ping.txt';
                  	mkdir $tmp_dir;
                  
                  	my $http_auth_user = 'xxxxxx';
                  	my $http_auth_pass = 'xxxxxx';
                  	my $zabbix_user    = 'xxxxxx';
                  	my $zabbix_pass    = 'xxxxxx';
                  	my $cookie_file    = "/tmp/zabbix_cookie.txt";
                  	my $cmd_get_cookie = join(" ",
                  		"wget --user=$http_auth_user --password=$http_auth_pass --save-cookies=$cookie_file",
                  		"--keep-session-cookies --post-data \"name=$zabbix_user&password=$zabbix_pass&enter=Enter\"",
                  		"-O $tmp_file -q $zbx_host/index.php?login=1");
                  
                  	print `$cmd_get_cookie`;
                  	print "\n\n";
                  
                  	my $cmd_get_image = "wget --user=$http_auth_user --password=$http_auth_pass --load-cookies=$cookie_file";
                  	while (my ($key, $value) = each(%image_sources)) {
                  		$tmp_cmd = join(" ", $cmd_get_image, "-O $tmp_dir/$key", "-q \"" . $value->{url} . "\"");
                  		print `$tmp_cmd`;
                  	}
                  	
                  	my $webserver_user = 'apache';
                  	my $webserver_host = '127.0.0.1';
                  	my $sync_dst       = "$webserver_user\@$webserver_host:/var/www/html/public/";
                  	my $cmd_sync_files = "rsync -ocvrtzh --delete-after --stats -e \"ssh -p 2222\" $tmp_dir $sync_dst";
                  	print `$cmd_sync_files`;
                  
                  	print `rm $tmp_dir/*`;
                  	rmdir $tmp_dir;
                  	unlink $cookie_file;
                  	unlink $tmp_file;
                  }
                  
                  sub sendMail() {
                  	open(MAIL, "|/usr/sbin/sendmail -t");
                  	## Mail Header
                  	print MAIL "To: $to\n";
                  	print MAIL "From: $from\n";
                  	print MAIL "Content-Type: text/html\n";
                  	print MAIL "Subject: $subject\n\n";
                  
                  	## print HTML header
                  	print MAIL "<html><head><title>$title</title></head>\n<body>\n\n";
                  
                  	## print HTML body
                  	print MAIL "
                  		<h2>$title</h2>
                  	";
                  
                  	while (my ($key, $value) = each(%image_sources)) {
                  		print MAIL "
                  			<br/>
                  			<br/>
                  			<h3>" . $value->{title} . "</h3>
                  			<img style=\"width: 460px; height: 180px;\" alt=\"" 
                  		  . $key
                  		  . "\" src=\""
                  		  . join("/", $zbx_public, $dirname_images_short, $key) . "\"/>
                  		";
                  	}
                  
                  	## print HTML footer
                  	print MAIL
                  	  "<br/><br/><br/><p style=\"font-size: 6px;\">© Copyright $year YOURDOMAIN Inc. All rights reserved. Optimized for mobile devices (HVGA)</p></body></html>";
                  	close(MAIL);
                  }
                  
                  getImages();
                  sendMail();

                  Comment

                  Working...