Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: Need to know the process to implement perl script into web application server.

by choroba (Cardinal)
on Apr 22, 2021 at 15:34 UTC ( [id://11131601]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Need to know the process to implement perl script into web application server.
in thread Need to know the process to implement perl script into web application server.

You removed sub result. Your code doesn't contain the nested subs anymore, but now you can't run the sub you need. Was it the right solution?

Take a step back. Start from a simple thing. Add one feature at a time, always test it didn't break. If you change several things at once, you don't know exactly which one is the culprit. For example, start with an empty page. Then add a form. Once it works, add calling the rest client. Once it works, add the spreadsheet. It's not a weakness to progress in small steps, it's a method that one needs to learn. You'll see it leads to the results faster than trying to write everything at once, in the end.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^6: Need to know the process to implement perl script into web application server.
by chandantul (Scribe) on Apr 22, 2021 at 17:24 UTC

    Sir, Please check my existing code, Yes, I am trying to do what you have explained, Can you please let me know how i can utlize my nested sub for calling my api?

    #!/usr/bin/env perl package Op; use strict; use warnings; use Win32::Process; ##use Net::LDAP; use REST::Client; use JSON::Parse ':all'; use MIME::Base64; use Term::ReadKey; use Data::Dumper; use MIME::Lite; use Net::SMTP; use Spreadsheet::XLSX; use Spreadsheet::ParseXLSX; use Excel::Writer::XLSX; use Config::Properties; use Data::Dumper; use List::Compare; use Array::Compare; use Storable qw/freeze/; use Data::Validate::IP; use Data::Table::Excel; use Excel::Writer::XLSX::Chart; use Win32::OLE::Const; use Spreadsheet::WriteExcel::Utility qw( xl_range_formula ); use Win32::OLE; use POSIX 'strftime'; use POSIX qw(strftime); use DateTime; use DateTime::Format::Strptime; use Try::Tiny; use feature qw{ say }; open my $fh, '<', "C:/PERL/" . "config.properties" or die "unable to o +pen configuration file"; my $properties = Config::Properties->new(); $properties->load($fh); my $value = $properties->getProperty('oktapreview.token'); my $baseurl = $properties->getProperty('oktaQA.baseURL'); my $from_address = 'chandan@aol.com'; my $to_address = 'chandan@bol.com'; my $subject = 'A message with 2 parts ...'; my $my_file_zip = 'C://PERL//'; my $mail_host = 'mail.aol.com'; my $pass = '1234567'; sub result { my ($args) = @_; my $appID = $args->{APPID}; my $datver = $args->{datetime}; my $email = $args->{Email}; my $date = strftime '%Y-%m-%d-%H-%M-%S', localtime; my $date3 = strftime '%Y-%m-%d' , localtime(time() - $datver*60*60 +); my $date4 = strftime '%Y-%m-%d' , localtime(time() - 24*60*60); my $apiurllog = $baseurl ."/users/sys/logs?"; my $client = REST::Client->new(); my @responsetext; my @responsetextall; my $sortor = "filter=eventType+eq+%22"; my $filter = "all.auth.sso"; my @responsalter; my $target = "%22+and+to.id+eq+%22"; my $strExcelFilename; my %header1 = ( -size => 10, ); sub api_call { $client->addHeader('Authorization',"SSWS $value"); $client->addHeader('Accept','application/json'); $client->addHeader('Content-type','application/json'); $client->GET($_[0]); } my $date2 = "%22&since=" . $date3 . "T00%3A00%3A00.000-04%3A00&until=" + . $date4 . "T23%3A59%3A59.000-04%3A00"; my $urlstringlog = $apiurllog . $sortor . $filter . $target . $appID . + $date2; $strExcelFilename = "C:/PERL/" . "My-File" . $date . ".xlsx"; my $your_file_zip = "My-File . $date . '.xlsx'"; api_call($urlstringlog); @responsetext = parse_json ($client->responseContent()); push @responsetextall, @responsetext; for my $i (0..$#responsetextall) { for my $j (0..$#{$responsetextall[$i]}) { my $responseid = $responsetextall[$i][$j]{act}{UID}; my $responsdisp = $responsetextall[$i][$j]{act}{Name}; push @responsalter, $responseid ; } } my $workbook = Excel::Writer::XLSX->new( $strExcelFilename ); my $format_bold = $workbook->add_format( bold => 1, size => 10, top=> +1, bottom=> 1 ); my $format2 = $workbook->add_format(%header1); my $worksheet = $workbook->add_worksheet('UserSSO-Data'); my $r = 1; my $r2 = 1; my $r3 = 1; foreach my $j (0..$#responsalter ) { $worksheet->write(0, 0, 'UserSSO-Total +-Users' ); $worksheet->write($r2, 0, $responsalter[$j]); $r2 += 1; } $workbook->close; print "Spreadsheet saved.\n"; ## Mail Functionality my $msg = MIME::Lite->new ( From => $from_address, To => $to_address, Subject => $subject, Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; $msg->attach ( Type => 'text/csv', Encoding => 'base64', Path => $my_file_zip, Filename => $your_file_zip, Disposition => 'attachment' ) or die "Error adding $your_file_zip: $!\n"; MIME::Lite->send('smtp', $mail_host, Timeout=>60,Auth=>'LOGIN',AuthUs +er=>$from_address,AuthPass=>$pass,Port => 25, Debug => 1); }
      Define the sub outside of the other sub:
      sub api_call { my ($client, $value, $url) = @_; $client->addHeader('Authorization',"SSWS $value"); $client->addHeader('Accept','application/json'); $client->addHeader('Content-type','application/json'); $client->GET($url); }

      and call it like

      api_call($client, $value, $urlstringlog);

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        Hello Sir, Thanks for your help but i was unable to password App id after entering the same in web FORM. Please check the API call and its missing with the APP id. After target id it should be visible between %22 and %22 , currently getting JSON error

        https://sso.abc.com/users/sys/logs?filter=eventType+eq+%22all.auth.sso +%22+and+target.id+eq+%22%22&since=2021-04-22T00%3A00%3A00.000-04%3A00 +&until=2021-04-21T23%3A59%3A59.000-04%3A00

        JSON error

        JSON error at line 1, byte 1/1259: Unexpected character '<' parsing in +itial state: expecting whitespace: 'n', '\r', '\t', ' ' or start of s +tring: '"' or digit: '0-9' or minus: '-' or start of an array or obje +ct: '{', '[' or start of literal: 't', 'f', 'n' at C:/Users/Documents +/Perl/webapp/bin/../lib/Op.pm line 98.

        Please check my current query.tt

        <form id="f1" method="post" action="/"> <div> <label for="APPID">APPID</label> <input id="APPID" name="APPID"> <label for="date">Time in Hours</label> <input id="date" name="date"> <label for="Email">Recipient Email</label> <input id="Email" name="Email"> </div> <button>Submit</button> </form>

        Please check my current code

        #!/usr/bin/env perl package Op1; use strict; use warnings; use Win32::Process; ##use Net::LDAP; use REST::Client; use JSON::Parse ':all'; use MIME::Base64; use Term::ReadKey; use Data::Dumper; use MIME::Lite; use Net::SMTP; use Spreadsheet::XLSX; use Spreadsheet::ParseXLSX; use Excel::Writer::XLSX; use Config::Properties; use Data::Dumper; use List::Compare; use Array::Compare; use Storable qw/freeze/; use Data::Validate::IP; use Data::Table::Excel; use Excel::Writer::XLSX::Chart; use Win32::OLE::Const; use Spreadsheet::WriteExcel::Utility qw( xl_range_formula ); use Win32::OLE; use POSIX 'strftime'; use POSIX qw(strftime); use DateTime; use DateTime::Format::Strptime; use Try::Tiny; use feature qw{ say }; open my $fh, '<', "C:/PERL/" . "config.properties" or die "unable to o +pen configuration file"; my $properties = Config::Properties->new(); $properties->load($fh); my $value = $properties->getProperty('oktapreview.token'); my $baseurl = $properties->getProperty('oktaQA.baseURL'); my $from_address = 'chandan@aol.com'; my $to_address = 'chandan@bol.com'; my $subject = 'A message with 2 parts ...'; my $my_file_zip = 'C://PERL//'; my $mail_host = 'mail.aol.com'; my $pass = '1234567'; my ($args) = @_; my $appID = $args->{APPID}; my $datver = $args->{date}; my $email = $args->{Email}; my $date = strftime '%Y-%m-%d-%H-%M-%S', localtime; my $date3 = strftime '%Y-%m-%d' , localtime(time() - $datver*60*60 +); my $date4 = strftime '%Y-%m-%d' , localtime(time() - 24*60*60); my $apiurllog = $baseurl ."/users/sys/logs?"; my $client = REST::Client->new(); my @responsetext; my @responsetextall; my $sortor = "filter=eventType+eq+%22"; my $filter = "all.auth.sso"; my @responsalter; my $target = "%22+and+target.id+eq+%22"; my $strExcelFilename; my %header1 = ( -size => 10, ); #sub api_call { # $client->addHeader('Authorization',"SSWS $value"); # $client->addHeader('Accept','application/json'); # $client->addHeader('Content-type','application/json'); # $client->GET($_[0]); #} sub api_call { my ($client, $value, $url) = @_; $client->addHeader('Authorization',"SSWS $value"); $client->addHeader('Accept','application/json'); $client->addHeader('Content-type','application/json'); $client->GET($url); } sub result { my $date2 = "%22&since=" . $date3 . "T00%3A00%3A00.000-04%3A00&until=" + . $date4 . "T23%3A59%3A59.000-04%3A00"; my $urlstringlog = $apiurllog . $sortor . $filter . $target . $appID . + $date2; print "My URL: $urlstringlog"; $strExcelFilename = "C:/PERL/" . "My-File" . $date . ".xlsx"; my $your_file_zip = "My-File . $date . '.xlsx'"; api_call($client,$value,$urlstringlog); @responsetext = parse_json ($client->responseContent()); push @responsetextall, @responsetext; for my $i (0..$#responsetextall) { for my $j (0..$#{$responsetextall[$i]}) { my $responseid = $responsetextall[$i][$j]{act}{UID}; my $responsdisp = $responsetextall[$i][$j]{act}{Name}; push @responsalter, $responseid ; } } my $workbook = Excel::Writer::XLSX->new( $strExcelFilename ); my $format_bold = $workbook->add_format( bold => 1, size => 10, top=> +1, bottom=> 1 ); my $format2 = $workbook->add_format(%header1); my $worksheet = $workbook->add_worksheet('UserSSO-Data'); my $r = 1; my $r2 = 1; my $r3 = 1; foreach my $j (0..$#responsalter ) { $worksheet->write(0, 0, 'UserSSO-Total +-Users' ); $worksheet->write($r2, 0, $responsalter[$j]); $r2 += 1; } $workbook->close; print "Spreadsheet saved.\n"; ## Mail Functionality my $msg = MIME::Lite->new ( From => $from_address, To => $to_address, Subject => $subject, Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; $msg->attach ( Type => 'text/csv', Encoding => 'base64', Path => $my_file_zip, Filename => $your_file_zip, Disposition => 'attachment' ) or die "Error adding $your_file_zip: $!\n"; MIME::Lite->send('smtp', $mail_host, Timeout=>60,Auth=>'LOGIN',AuthUs +er=>$from_address,AuthPass=>$pass,Port => 25, Debug => 1); } #__PACKAGE__

        I am getting below warning

        Use of uninitialized value $datver in multiplication (*) at Op1.pm line 52.

        2021-04-23 Athanasius fixed over-long code lines.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2024-04-25 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found