getGraphsFDN.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/perl
  2. # Recuperation des graphiques de consommation de FDN a partir des identifiants
  3. # d'adherent du FAI en marque blanche (depuis le 31/10/11, l'identification avec
  4. # le login radius d'un ligne n'est plus possible).
  5. #
  6. # USAGE: ./% prenom nom
  7. use strict;
  8. use warnings;
  9. use WWW::Mechanize;
  10. my $mech = WWW::Mechanize->new(
  11. agent => 'SI-LDN'
  12. );
  13. if(@ARGV != 2) {
  14. print "Usage: $0 prenom nom\n";
  15. exit 1;
  16. }
  17. # Identifiants d'adherent du FAI en marque blanche
  18. my $adh_login = '';
  19. my $adh_pwd = '';
  20. # Abonne concerne
  21. my $prenom = $ARGV[0];
  22. my $nom = $ARGV[1];
  23. # Nom composes, voir https://repo.ldn-fai.net/redmine/issues/100
  24. $nom =~ s/ /./g;
  25. eval {
  26. # Identification sur le SI de FDN
  27. $mech->get("https://vador.fdn.fr/adherents/index.cgi?adhlogin=$adh_login&adhpasswd=$adh_pwd&do=yes");
  28. };
  29. if($@) {
  30. print "<div id='error'>Le service semble indisponible actuellement,<br />la version des graphs consultés dernièrement est affichée.</div>";
  31. exit 1;
  32. }
  33. # Recuperation de l'ID de session dans l'URL de redirection (aucun cookie)
  34. my $graphs_uri = $mech->uri();
  35. # Il faut obligatoirement passer par cette page pour faire generer les graphs et
  36. # s'eviter un "session invalide"
  37. $graphs_uri =~ s/-in/-stats/;
  38. $mech->get($graphs_uri);
  39. # Recuperation du graph de conso totale
  40. $graphs_uri =~ s/-stats/-statimg/;
  41. $mech->get($graphs_uri."&img=total.rrd&freq=daily", ':content_file' => "total.png");
  42. $mech->get($graphs_uri."&img=total-fai-locaux.rrd&freq=daily", ':content_file' => "failocaux.png");
  43. $mech->get($graphs_uri."&img=moyenne&freq=daily", ':content_file' => "moyenne.png");
  44. # Recuperation des graphs individuels
  45. $graphs_uri .= "&img=$prenom.$nom%40fdn.nerim.rrd&freq=";
  46. for (qw(daily weekly monthly yearly)) {
  47. $mech->get($graphs_uri.$_, ':content_file' => "$_.png");
  48. }
  49. exit 0;