31.3.1 Scripting Blackouts

It is also possible to manage blackouts from the command line, or a script. The examples listed in this section all use curl. You can run the commands from the command line or add to a text file and save it as *.sh or *.bat depending on your platform.

Note

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

The following blackout types are described:

  • Server Blackout: describes how to apply or remove a blackout on a MySQL instance.

  • Group Blackout: describes how to apply or remove a blackout on a MySQL Enterprise Monitor groujp.

  • Agent Blackout: describes how to apply or remove a blackout on a MySQL Enterprise Monitor Agent and, recursively, on all MySQL instances monitored by the agent.

  • Blackout Status: describes how to check the blackout status on the agent, group, or MySQL instance.

Note

Restarting MySQL Enterprise Service Manager or MySQL Enterprise Monitor Agent does not remove an applied blackout.

Server Blackout

The blackout command enables you to blackout individual MySQL instances.

To blackout an individual MySQL instance you must provide the following:

  • --user: the username and password of the Service Manager user running the command. Ensure this user has the correct rights to perform blackouts.

  • The URL of the Service Manager's rest API. For example: "https://servicemanager:18443/rest"

  • command=blackout: the blackout command.

  • One of the following:

    • server_name=ServerName: the name of the server to blackout.

    • server_uuid=AlphanumericString: the UUID of the MySQL instance to blackout.

To blackout a server using the server_name, use the following command:

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout" --data-urlencode "server_name=servername:3306" 
  --data-urlencode "blackout_state=true"

To blackout a server using the server_uuid, use the following command:

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout" 
  --data-urlencode "server_uuid=62e74f29-526a-11ba-77fb-0242xy112504" 
  --data-urlencode "blackout_state=true"

To remove the blackout, run the same command, with "blackout_state=false". For example:

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout" 
  --data-urlencode "server_uuid=62e74f29-526a-11ba-77fb-0242xy112504" 
  --data-urlencode "blackout_state=false"

It is also possible to blackout all the MySQL instances monitored by a specific Agent. for more information, see Agent Blackout.

Group Blackout

The blackout command enables you to blackout groups of MySQL instances. For more information on MySQL Enterprise Service Manager Groups, see Chapter 18, Managing Groups of Instances.

To blackout a group of MySQL instances you must provide the following:

  • --user: the username and password of the Service Manager user running the command. Ensure this user has the correct rights to perform blackouts.

  • The URL of the Service Manager's rest API. For example: "https://servicemanager:18443/rest"

  • command=blackout: the blackout command.

  • group_name=GroupName: the name of the group to blackout.

The following command blackouts all MySQL instances in the group named Group 1.

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest"
  --data-urlencode "command=blackout" --data-urlencode "group_name=Group 1" 
  --data-urlencode "blackout_state=true"

To remove the blackout, run the same command, with "blackout_state=false".

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest"
  --data-urlencode "command=blackout" --data-urlencode "group_name=Group 1" 
  --data-urlencode "blackout_state=false"

Agent Blackout

The command blackout enables you to blackout an Agent, or an Agent and all the MySQL instances it is currently monitoring.

To blackout an agent you must provide the following:

  • --user: the username and password of the Service Manager user running the command. Ensure this user has the correct rights to perform blackouts.

  • The URL of the Service Manager's rest API. For example: "https://servicemanager:18443/rest"

  • command=blackout: the blackout command.

  • id=alphanumericString: the id of the Agent to blackout.

To blackout an agent, run the following command:

   curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest"
  --data-urlencode "command=blackout" 
  --data-urlencode "agent_id=1e365f83-b703-4588-9472-877c90a2c49f" 
  --data-urlencode "blackout_state=true"

To blackout an Agent and all the MySQL instances it monitors, run the following command:

   curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest"
  --data-urlencode "command=blackout" 
  --data-urlencode "agent_id=1e365f83-b703-4588-9472-877c90a2c49f" 
  --data-urlencode "blackout_state=true" --data-urlencode "recursive=true"

Blackout Status

The command blackout_status enables you to check if an agent or MySQL instance is currently blacked out.

To check the blackout status you must provide the following:

  • --user: the username and password of the Service Manager user running the command. Ensure this user has the correct rights to perform blackouts.

  • The URL of the Service Manager's rest API. For example: "https://servicemanager:18443/rest"

  • command=blackout_status: the blackout status command.

  • id=alphanumericString: the id of the Agent or MySQL instance being checked.

  • asset_type: one of the following:

    • agent.Agent: to check the blackout status of the Agent.

    • mysql.MysqlServer: to check the blackout status of the MySQL instance.

The following command checks the blackout status of an agent:

  curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout_status" 
  --data-urlencode "id=1e365f83-b703-4588-9472-877c90a2c49f" 
  --data-urlencode "asset_type=agent.Agent"

The following command checks the blackout status of a MySQL instance:

 curl -G -k --user myadmin:mypassword "https://servicemanager:18443/rest" 
  --data-urlencode "command=blackout_status" 
  --data-urlencode "id=750cead2-441d-11ea-b3e7-dfdaa5ad712e" 
  --data-urlencode "asset_type=mysql.MysqlServer"