1

hope you can help...

We have cacti setup and running perfectly, we want to give cacti graphs to our clients, so we got a script to do so. However its failing to pull in the graphs. The script is setup and talking to our cacti, but we are not getting the display of the actual graphs.

You can see the issue here - http://noc.dediport.com/cacti/switchporttranslate.php?host4&switchport=Fa0/1&period=daily

That should be displaying a graph, this is the response I got from the script creators:

The next step is looking at the Cacti side. http://noc.dediport.com/cacti/switchporttranslate.php?host4&switchport=Fa0/1&period=daily shows that the PHP is not being interpreted so the source is being returned. I'm afraid we can't tell why from the results returned, you'll need to examine why from your logs.

Although they have been helpful, I have still not got to the bottom of this issue. I am sure it is a simple mistake but I would appreciate any help.

FYI Cacti is running on centos 6.5

Dediport
  • 21
  • 5

2 Answers2

0

Here is curl sample code to pull cacti graph for client on desired website/web portal Note your need to preserve session and see for any other variables used during authentication, set it to successfully login into system

$username = 'dipen';
    $password = 'yourpassword';
    $postinfo = 'login_username='.$username.'&login_password='.$password;

    $url1 = 'https://yourhost/graph.php?action=view&rra_id=all&local_graph_id=5813';
    $url = "https://yourhost/";

    //path to save cookie info temporarily 
    $path = base_url()."img/ctemp";
    $cookie = "cookie.txt";  

    $postdata = "login_username=".$username."&login_password=".$password."&action=login";
    $ch =curl_init();
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
    curl_setopt($ch,CURLOPT_TIMEOUT, 60);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_COOKIESESSION, true);
    curl_setopt($ch,CURLOPT_COOKIEJAR, $cookie);
     curl_setopt($ch,CURLOPT_COOKIEFILE, $path);
    curl_setopt ($ch, CURLOPT_REFERER, $url);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
    curl_setopt ($ch, CURLOPT_POST, 1); 
    $result = curl_exec ($ch);
    if (curl_error($ch)) {
        echo curl_error($ch);
    } 
    //var_dump($result);  


    curl_setopt($ch, CURLOPT_URL, $url1);
    curl_setopt($ch, CURLOPT_POST, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "");
    $answer = curl_exec($ch);
    if (curl_error($ch)) {
        echo curl_error($ch);
    }

    if(!empty($corporate_graph_id))
    {
        echo '<img src="https://yourhost/graph_image.php?action=view&local_graph_id=$corporate_graph_id&rra_id=5" />';

        echo '<img src="https://yourhost/graph_image.php?action=view&local_graph_id=5813&rra_id=1" />';

        echo '<img src="https://yourhost/graph_image.php?action=view&local_graph_id=5813&rra_id=2" />';

        echo '<img src="https://yourhost/graph_image.php?action=view&local_graph_id=5813&rra_id=3" />';

        echo '<img src="https://yourhost/graph_image.php?action=view&local_graph_id=5813&rra_id=4" />'; 
    }
    curl_close($ch);
Dipen
  • 1,056
  • 1
  • 19
  • 36
0

There was some link issue on my previous example so i downloaded the image on my server and displayed it from there here is my code

     $username = 'dipen';
    $password = 'yourpassword';

    $url = "https://graph.yourdomain.com/";
    $cookie = "cookie.txt";  
    $path = "tempcookie";

    $postdata = "login_username=".$username."&login_password=".$password."&action=login";

    $ch =curl_init();
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
    $agent = $_SERVER["HTTP_USER_AGENT"];
    curl_setopt($ch,CURLOPT_USERAGENT, $agent);
    curl_setopt($ch,CURLOPT_TIMEOUT, 60);
    curl_setopt($ch,CURLOPT_COOKIESESSION, true);
    curl_setopt ($ch,CURLOPT_REFERER, $url);
    curl_setopt ($ch,CURLOPT_POST, 1); 
    curl_setopt ($ch,CURLOPT_POSTFIELDS, $postdata);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch,CURLOPT_COOKIEJAR, $path.'/'.$cookie);
    curl_setopt($ch,CURLOPT_COOKIEFILE, base_url().$path.'/'.$cookie); 
    $result = curl_exec ($ch);
    if (curl_error($ch)) {
        echo curl_error($ch);
    }

    if(!empty($corporate_graph_id))
    {
        $corporate_graph_id = $corporate_graph_id[0]['grpah_id'];

        $url1 =' https://graph.yourdomain.com/graph_image.php?action=view&local_graph_id='.$corporate_graph_id.'&rra_id=3';

        curl_setopt($ch, CURLOPT_URL, $url1);
        curl_setopt($ch, CURLOPT_POST, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "");
        curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
        $answer = curl_exec($ch);
        if (curl_error($ch)) {
            echo curl_error($ch);
        }

        $fp = fopen($path.'/'.$corporate_graph_id.'.jpg','w');
        fwrite($fp, $answer);
        fclose($fp);


        $img_path = base_url().$path.'/'.$corporate_graph_id.'.jpg'; 

        echo '<img src="'.$img_path.'" /><br/>';

    }
    curl_close($ch);
Dipen
  • 1,056
  • 1
  • 19
  • 36