Automated indexing Jira 6.2

At jira 6.2 i get:

Creating connection to [https://**********************/]... 
 
Use of uninitialized value in string eq at reindex_test.pl line 34 (#1)
 
    (W uninitialized) An undefined value was used as if it were already
 
    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
 
    To suppress this warning assign a defined value to your variables.
 
     
 
    To help you figure out what was undefined, perl will try to tell you
 
    the name of the variable (if any) that was undefined.  In some cases
 
    it cannot do this, so it also tells you what operation you used the
 
    undefined value in.  Note, however, that perl optimizes your program
 
    anid the operation displayed in the warning may not necessarily appear
 
    literally in your program.  For example, "that $foo" is usually
 
    optimized into "that " . $foo, and the warning will refer to the
 
    concatenation (.) operator, even though there is no . in
 
    your program.
 
     
 
Uncaught exception from user code:
 
        Could not login to jira, verify username and password!

Here is the Code (based on: https://answers.atlassian.com/questions/171272/jira-automated-reindex-script-for-version-5-and-later?page=1#283284):

#!/usr/bin/perl
###################################################################################
# Re-Index.pl by Jason Hensler
# Starts re-index job for jira. Tested with JIra 5.2.4 and 6.0.7
###################################################################################
  
#disable ssl verfication, using this for self-signed cert otherwise comment out.
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
use warnings;
use diagnostics;
use Data::Dumper; 
use LWP::UserAgent;
  
# Change these
my $user = "*****";
my $pass = "******";
my $jira_url = "https://*************************/"; 
my $cookie_jar = $ENV{'HOME'}; #change this if you need to, should only be need is there is a permissions issue.
my $index_type = 1; #This is for jira 5.2 and above. Set to 1 for background re-index or 0 for locking index.
my $error = 0;
  
  
#setup initial connection paramaters
my $status;
print("Creating connection to [$jira_url]... \n");
my $ua = LWP::UserAgent->new;
$ua->cookie_jar({ file => "$cookie_jar/\.cookies.txt" });
$ua->default_header('X-Atlassian-Token' => 'no-check');
  
  
#do login
$status = $ua->post($jira_url.'secure/admin/IndexAdmin.jspa', [ 'os_username'   => $user, 'os_password'  => $pass]);
if($status->header('X-Seraph-LoginReason') eq "AUTHENTICATED_FAILED" || $status->code !=200) {die("Could not login to jira, verify username and password!\n");}
else {
    print("Successfully logged in to Jira.\n");
    #do websudo
    $status = $ua->post($jira_url.'secure/admin/WebSudoAuthenticate.jspa',[ 'webSudoPassword'   => $pass]);
  
    # I'm using the http code here because the user header check stays ok and I didn't want to grep the output for an error... 
    # If we pass sudo check we get redirected to /secure/ and code is 302, otherwise we get served an error page with status 200
    if($status->code != 302) { 
        unlink('$cookie_jar/.cookies.txt');
        print("We did not sudo properly, check that your password is good and the your user is an admin!\n");
        $error = 1;
    } else {
        print("Successfully passed websudo, kicking off indexing... ");
        #do re-index
        if($index_type == 1) {$index_type='background';}
        $status = $ua->post($jira_url.'IndexReIndex.jspa', [ 'indexPathOption' => 'DEFAULT','Re-Index' =>'Re-Index', 'indexingStrategy' => $index_type]);
        if($status->code != 302) { 
            print("Could not start re-index, check that your password is good and the your user is an admin!\n");
            $error = 1;
        } else {
            print("Re-index has started.\n");
            print ("Task url: ".$status->header('location')."\n");
            my $finished = 0;
            my $temp_file = "out.html";
            while ($finished eq 0) {
                my $progress = $ua->mirror($status->header('location'),$temp_file);
                sleep(5);
                open(my $tmp, "<", $temp_file);
                while(eof($tmp) != 1) {
                    my $line = readline($tmp);
                    $line =~ s/^\s+|\s+$//g;
                    #print($line);
                    if ( substr($line,0,15) eq "Re-indexing is ") {
                        print ("Reindex is at ".substr($line,15,3)."\n");
                        if(substr($line,15,3) eq "100") {
                            $finished = 1;
                            print ("DONE!\n");
                        }
                    }
                }
                unlink($temp_file);
                sleep(5);
            }
              
            $error = 0;
        }
    }
}
unlink('$cookie_jar/.cookies.txt');
exit $error;

9 answers

This widget could not be displayed.

@Julian Bonkamp

You had your question in the right place the first time. Looks like it's not happy with:
if($status->header('X-Seraph-LoginReason') eq "AUTHENTICATED_FAILED"

Check to make sure that your jira $jira_url is correct, should be https://jira_server/jira. The "/jira/" at the end is important and the url must end in "/". If that does not fix it, add the line of code before the if statment:
echo(Dumper($status));

This will output the entire content of the $status httpd call. You will get raw http resonse data but, it should show any error messages or headers that the server is returning.

This widget could not be displayed.

I am a perl newbie :(

i added it like this:

#do login
$status = $ua->post($jira_url.'secure/admin/IndexAdmin.jspa', [ 'os_username'   => $user, 'os_password'  => $pass]);
echo(Dumper($status));
if($status->header

i get error:

Undefined subroutine &main::echo called at reindex_test.pl line 34 (#1)
    (F) The subroutine indicated hasn't been defined, or if it was, it has
    since been undefined.
    
Uncaught exception from user code:
        Undefined subroutine &main::echo called at reindex_test.pl line 34.

opps, sorry I've made a mistake (been working on a lot of php latley). The code should be:

print(Dumper($status));
$status = $ua->post($jira_url.'secure/admin/IndexAdmin.jspa', [ 'os_username'   => $user, 'os_password'  => $pass]);

the script don't stops automatically. Is it possible? We want to trigger it every day via an automizer.

This widget could not be displayed.

it works with "print"

This widget could not be displayed.

my fault... :( our testsystem has no SSL ^^ only http... now it works

This widget could not be displayed.

i get 404:

$VAR1 = bless( {

'_msg' => 'Not Found'

But the URL should be correct. our Jira listens not on /jira/ it works under https://<SERVER>/jira-one-test/

This widget could not be displayed.

the script don't stops automatically. Is it possible? We want to trigger it every day via an automizer.

The script is looking for the string: "Re-indexing is 100%" before it "finishes". If you're Jira is running an non-English (us) language page then this string might need to be changed on line 59. You could also change line 56 to my$finished= 0;, this will cause the script to finish before jira does.

This widget could not be displayed.

in the out.html it looks like:

div class="pb_section"&gt;
                    &lt;span&gt;

                        Bearbeitung läuft: Issue Index:

                    Die Neuindizierung ist zu 33% abgeschlossen.
                    &lt;/span&gt;
               &lt;/div&gt;

This widget could not be displayed.

i changed it to

if ( substr($line,0,15) eq "Die Neuindizierung ist zu") {

but it does not work..

The 15 needs to be changed to 26 within that line and you need a space after "zu", should look like this:

if ( substr($line,0,26) eq "Die Neuindizierung ist zu ") {

The reason for this is I am checking only the characters 0 to 26 to be equal to "Die Neuindizierung ist zu ".

You also need to change these lines:

print ("Reindex is at ".substr($line,15,3)."\n");
                        if(substr($line,15,3) eq "100") {

To:

print ("Reindex is at ".substr($line,26,3)."\n");
if(substr($line,26,3) eq "100") {

This widget could not be displayed.

it works :) thank you!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in Statuspage

What are your best incident management tips and stories? #HugOps

 👋Community members! Downtime happens. And great incident response takes a village. Teams like Support, Dev, SRE, Ops, IT, and Marketing have to come together to resolve the problem while keep...

39 views 2 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you