6.4.1 Scripting Blackouts

You can write a script to black out a server, rather than opening a web browser and typing entries into the address bar. This section documents a sample blackout script that can be run from the command line.

Create the following file and save it as blackout.pl.

  #!/usr/bin/perl

  use LWP 5.64;

  # USAGE: blackout.pl servicemanager:18443 admin password servername:3306 true

  # $ARGV[0] = management server hostname:port
  # $ARGV[1] = management server username
  # $ARGV[2] = management server password
  # $ARGV[3] = mysqld managed instance server name and port
  # $ARGV[4] = blackout state (true/false)


  my $browser = LWP::UserAgent->new;
  $browser->credentials(
    $ARGV[0],
    'MEM',
    $ARGV[1],
    $ARGV[2]
  );

  my $url = URI->new('https://'.$ARGV[0].'/rest');

  $url->query_form( # And here the form data pairs:
    'command' => 'blackout',
    'server_name' => $ARGV[3],
    'blackout_state' => $ARGV[4]
  );

  my $response = $browser->post( $url );

  if (!$response->is_success) {
    die $response->status_line . "\n";
  }

  if ($response->content =~ /UserUnauthorizedException/ ||
       $response->content =~ /ServerDoesNotExistException/) { 
  	die $response->content;
  }
Note

Windows users can omit the initial #! line.

On Unix systems, use the chmod +x blackout.pl command to make the file executable.

At the command line, enter blackout.pl servicemanager:18443 admin password servername:3306 true.

Check the configuration_report.txt file for the host name and port to use. Specify the correct port for the Tomcat server. Specify the server to black out using the name that appears in the Server Tree, including the colon and port number as shown in the preceding example. Specify the name of a user who is a "manager". A user with "dba" rights cannot black out a server, and the script does not display any error in this case.

To confirm that a server is blacked out, check that its name is greyed out in the Monitor UI. To end the blackout, run the same script, changing the final argument to false.

Note

Restarting MySQL Enterprise Monitor does not reactivate a blacked out server.