Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/opt/SP/perl/perl-5.18.2-reloc/bin/perl -w
- use strict;
- use warnings;
- use LWP;
- use Time::Piece;
- use Time::HiRes qw[gettimeofday tv_interval];
- my $time1=[gettimeofday()];
- my $browser = LWP::UserAgent->new;
- $browser->agent($0.' $Revision: 778 $');
- $browser->cookie_jar( {} );
- my @ns_headers = (
- 'Accept' => 'text/html, text/plain, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*',
- 'Accept-Charset' => 'iso-8859-1,*',
- 'Accept-Language' => 'en-US',
- );
- my $login= "https://mywebsite.com/opensso/rest/1.0/opensso/identity/authenticate";
- my $logout="https://mywebsite.com/opensso/rest/1.0/opensso/identity/logout";
- my $response;
- # Logon
- $response = $browser->post(
- $login,
- [
- username => 'test@123',
- password => 'pssd123',
- ],
- @ns_headers);
- do_die("login: ".$response->status_line) unless $response->is_success;
- do_die("No token received ".$response->content) unless $response->content=~ /^token.id=(S+)$/;
- # Logoff
- my $token= $1;
- $response = $browser->post(
- $logout,
- [
- subjectid => $token,
- ],
- @ns_headers);
- do_die("logout: ".$response->status_line) unless $response->is_success;
- my $date = localtime->strftime('%y%m%d');
- my $time = localtime->strftime('%R');
- my $milliseconds = tv_interval($time1);
- open (MYFILE, '>>/var/SP/data/reporting/customersystems/result_KPI.txt');
- print MYFILE "$date $time GIS sso_logon_logoff 0 $millisecondsn";
- close (MYFILE);
- exit 0;
- sub do_die {
- my($text)= @_;
- # $text=~ s/n/\n/g;
- print $text;
- open (MYFILE, '>>/var/SP/data/reporting/customersystems/result_KPI.txt');
- print MYFILE "$date $time GIS sso_logon_logoff 1 $millisecondsn";
- close (MYFILE);
- exit 1;
- }
- 181212 09:11 GIS sso_logon_logoff 0 0.466719
- 181212 09:12 GIS sso_logon_logoff 0 0.483316
- 181212 09:13 GIS sso_logon_logoff 0 0.482076
- 181212 09:14 GIS sso_logon_logoff 0 0.515636
- 181212 09:15 GIS sso_logon_logoff 0 0.490774
- 181212 09:16 GIS sso_logon_logoff 0 0.449388
- GIS sso_logon_logoff 1
- 181212 09:18 GIS sso_logon_logoff 0 0.543591
- 181212 09:19 GIS sso_logon_logoff 0 0.446938
- 181212 09:20 GIS sso_logon_logoff 0 0.683515
- GIS sso_logon_logoff 1
- 181212 09:22 GIS sso_logon_logoff 0 0.453028
- GIS sso_logon_logoff 1
- GIS sso_logon_logoff 1
- GIS sso_logon_logoff 1
- GIS sso_logon_logoff 1
- GIS sso_logon_logoff 1
Add Comment
Please, Sign In to add comment