Authentication
POST /login
: Authenticate and obtain an AuthToken for subsequent API requests.
Jobs
GET /Job
: Retrieve a list of jobs and their statuses.GET /Job/{jobId}
: Retrieve details of a specific job.POST /Job
: Create a new job.PUT /Job/{jobId}
: Modify an existing job.DELETE /Job/{jobId}
: Delete a job.
Backups
GET /Backup
: Retrieve a list of backups and their statuses.GET /Backup/{backupId}
: Retrieve details of a specific backup.POST /Backup
: Create a new backup.PUT /Backup/{backupId}
: Modify an existing backup.DELETE /Backup/{backupId}
: Delete a backup.
Clients
GET /Client
: Retrieve a list of clients.GET /Client/{clientId}
: Retrieve details of a specific client.POST /Client
: Add a new client.PUT /Client/{clientId}
: Modify an existing client.DELETE /Client/{clientId}
: Delete a client.ID
GET <webservice>/Client/{clientId} HTTP/1.1
Name
GET <webservice>/Client/byName(clientName='{clientName}') HTTP/1.1
Agents
GET /Agent
: Retrieve a list of agents.GET /Agent/{agentId}
: Retrieve details of a specific agent.POST /Agent
: Add a new agent.PUT /Agent/{agentId}
: Modify an existing agent.DELETE /Agent/{agentId}
: Delete an agent.
Media
GET /Media
: Retrieve a list of media (tapes, disks, etc.).GET /Media/{mediaId}
: Retrieve details of a specific media.POST /Media
: Add a new media.PUT /Media/{mediaId}
: Modify an existing media.DELETE /Media/{mediaId}
: Delete a media.
Storage Pools
GET /StoragePool
: Retrieve a list of storage pools.GET /StoragePool/{storagePoolId}
: Retrieve details of a specific storage pool.POST /StoragePool
: Add a new storage pool.PUT /StoragePool/{storagePoolId}
: Modify an existing storage pool.DELETE /StoragePool/{storagePoolId}
: Delete a storage pool.
Alerts
GET /Alert
: Retrieve a list of alerts.GET /Alert/{alertId}
: Retrieve details of a specific alert.POST /Alert
: Add a new alert.PUT /Alert/{alertId}
: Modify an existing alert.DELETE /Alert/{alertId}
: Delete an alert.
Reports
GET /Report
: Retrieve a list of available reports.POST /Report
: Generate a new report.
Schedules
GET /Schedule
: Retrieve a list of schedules.GET /Schedule/{scheduleId}
: Retrieve details of a specific schedule.POST /Schedule
: Add a new schedule.PUT /Schedule/{scheduleId}
: Modify an existing schedule.DELETE /Schedule/{scheduleId}
: Delete a schedule.APIs that you can use to find cluster details:
GET /commcell/entities/clients
- This API retrieves information about all the clients registered with the CommCell environment, including cluster clients.
GET /commcell/entities/clients/{clientId}
- This API retrieves detailed information about a specific client, including cluster clients, based on the provided
clientId
.
- This API retrieves detailed information about a specific client, including cluster clients, based on the provided
GET /commcell/entities/virtualservers
- This API retrieves information about all the virtual servers configured in the CommCell environment, which can include cluster nodes.
GET /commcell/entities/virtualservers/{virtualServerId}
- This API retrieves detailed information about a specific virtual server, which can be a cluster node, based on the provided
virtualServerId
.
- This API retrieves detailed information about a specific virtual server, which can be a cluster node, based on the provided
GET /commcell/entities/mediaagents
- This API retrieves information about all the media agents configured in the CommCell environment, which can include cluster nodes acting as media agents.
GET /commcell/entities/mediaagents/{mediaAgentId}
- This API retrieves detailed information about a specific media agent, which can be a cluster node, based on the provided
mediaAgentId
.
- This API retrieves detailed information about a specific media agent, which can be a cluster node, based on the provided
GET /commcell/entities/commservers
- This API retrieves information about all the CommServers configured in the CommCell environment, which can include cluster nodes acting as CommServers.
GET /commcell/entities/commservers/{commServerId}
- This API retrieves detailed information about a specific CommServer, which can be a cluster node, based on the provided
commServerId
.
- This API retrieves detailed information about a specific CommServer, which can be a cluster node, based on the provided
Please note that the actual endpoint URLs and request/response formats may vary depending on the CommVault version and configuration. It's recommended to refer to the official CommVault documentation or API reference for the most up-to-date and accurate information.
- After the authentication request, we check the status code of the response. If it's 200 (OK), we proceed with the API requests. Otherwise, we print an error message with the status code.
- For the agent jobs API request, we check the status code of the response. If it's 200 (OK), we process the response data. Otherwise, we print an error message with the status code.
- For the backups API request, we check the status code of the response. If it's 200 (OK), we process the response data. Otherwise, we print an error message with the status code.
By checking the status codes, we can handle different error scenarios and provide more informative error messages if something goes wrong with the API requests.
import requests
import json
# CommVault API endpoint and credentials
api_endpoint = "https://commvault.example.com/webconsole/api"
username = "your_username"
password = "your_password"
# Authentication
auth_url = f"{api_endpoint}/login"
auth_payload = {
"username": username,
"password": password
}
auth_response = requests.post(auth_url, json=auth_payload, verify=False)
auth_token = auth_response.headers.get("AuthToken")
# Set headers for subsequent API requests
headers = {
"AuthToken": auth_token,
"Content-Type": "application/json"
}
# Monitor agent jobs
agent_jobs_url = f"{api_endpoint}/Job"
agent_jobs_response = requests.get(agent_jobs_url, headers=headers, verify=False)
agent_jobs_data = agent_jobs_response.json()
for job in agent_jobs_data["jobSummariesValue"]:
job_id = job["jobId"]
job_status = job["jobStatus"]["status"]
if job_status == "failed" or job_status == "stopped":
print(f"Job {job_id} is {job_status}")
# Monitor backups
backups_url = f"{api_endpoint}/Backup"
backups_response = requests.get(backups_url, headers=headers, verify=False)
backups_data = backups_response.json()
for backup in backups_data["backupSummariesValue"]:
backup_id = backup["backupId"]
backup_status = backup["backupStatus"]["status"]
if backup_status == "failed" or backup_status == "stopped":
print(f"Backup {backup_id} is {backup_status}")
Here's how the code works:
- First, we define the CommVault API endpoint and provide our username and password for authentication.
- We send a POST request to the
/login
endpoint to obtain an authentication token. - We set the
AuthToken
andContent-Type
headers for subsequent API requests. - To monitor agent jobs, we send a GET request to the
/Job
endpoint and iterate through thejobSummariesValue
list in the response. If a job has a status of "failed" or "stopped", we print a message with the job ID and status. - To monitor backups, we send a GET request to the
/Backup
endpoint and iterate through thebackupSummariesValue
list in the response. If a backup has a status of "failed" or "stopped", we print a message with the backup ID and status.
Note that you'll need to replace "your_username"
and "your_password"
with your actual CommVault credentials, and "https://commvault.example.com/webconsole/api"
with the correct API endpoint for your CommVault instance.
Also, make sure you have the requests
library installed (pip install requests
) before running this code.
In Commvault, you can use the following APIs to check job statuses:
Job Manager API: This API provides endpoints to retrieve information about jobs, including their statuses. You can use endpoints like
/JobManager/Job
to list all jobs or filter by specific criteria such as client, agent, or job status.Client Computer Group API: If you have client computer groups set up in Commvault, you can use this API to retrieve information about them, including the status of associated jobs.
Alerts API: The Alerts API allows you to query for alerts generated by Commvault, which may include alerts related to job failures or other issues.
Event Viewer API: This API provides access to events generated by Commvault operations, including job-related events that can indicate success or failure.
By leveraging these APIs, you can effectively monitor job statuses and identify any failed agents or other issues within your Commvault environment.
-----------------------------------------------------------------------------------------
Ensuring the health of a Commvault environment via API involves checking various aspects such as job statuses, storage usage, client connectivity, and more. Here are several ways to do this along with examples in Python:
- Check Job Statuses:
- API Endpoint:
/JobManager/Job
- Objective: Ensure backup, restore, and other jobs are completing successfully.
- Example Code:
- Check Storage Usage:
- API Endpoint:
/MediaAgent/Media
- Objective: Ensure storage utilization is within acceptable limits.
- Example Code:
- Check Client Connectivity:
- API Endpoint:
/Client
- Objective: Ensure clients are connected and communicating properly.
- Example Code:
- Check Storage Policy Usage:
- API Endpoint:
/StoragePolicy
- Objective: Ensure storage policies are being applied correctly.
- Example Code:
- Event Viewer API:
- API Endpoint:
/EventViewer/Events
- Objective: Monitor system events and errors.
- Example Code:
- Alerts API:
- API Endpoint:
/Alerts
- Objective: Check for any active alerts in the system.
- Example Code:
- Client Computer Group API:
- API Endpoint:
/ClientGroup
- Objective: Ensure client computers are organized into groups properly.
- Example Code:
- Agent API:
- API Endpoint:
/Agent
- Objective: Check the status and health of agents installed on client computers.
- Example Code:
- Backup Recovery API:
- API Endpoint:
/JobManager/Job
- Objective: Monitor backup and recovery jobs for success and failure.
- Example Code: (Already provided in previous response)
- API Endpoint:
These examples demonstrate how you can use Python with the requests library to query different aspects of the Commvault environment via API and ensure its health across various scenarios. Adjust the endpoints and parameters based on your specific requirements and API documentation.
=======================================
import requests # Replace with your Commvault environment details commvault_url = "https://<your_commvault_server>/webservice/" username = "<your_username>" password = "<your_password>" # Client and VM details client_name = "<client_name>" vm_name = "<vm_name>" # Define the subclient details (replace with your desired values) subclient_name = "My Subclient" backup_set_name = "DefaultBackupSet" content_type = "VMName" # Can be "VMName" or "DATASTORE" for Datastore content def get_auth_token(): """ Retrieves an authentication token from Commvault. """ url = commvault_url + "login" auth = (username, password) headers = {"Content-Type": "application/json"} response = requests.post(url, auth=auth, headers=headers) response.raise_for_status() # Raise exception for non-200 status codes return response.json()["authenticationToken"] def add_subclient(): """ Adds a subclient to the specified client VM. """ auth_token = get_auth_token() headers = { "Authorization": f"AuthToken {auth_token}", "Content-Type": "application/xml" # Body format for add subclient } # Prepare the XML request body (replace with your specific content details) body = f""" <subclient> <appName>Virtual Server</appName> <subClientEntity> <subClientProperties> <clientName>{client_name}</clientName> <subClientName>{subclient_name}</subClientName> <backupsetName>{backup_set_name}</backupsetName> <instanceName>DefaultInstanceName</instanceName> <content> <vmContent> <type>{content_type}</type> <displayName>{vm_name}</displayName> </vmContent> </content> </subClientProperties> </subClientEntity> </subclient> """ url = commvault_url + "Subclient" response = requests.post(url, headers=headers, data=body) response.raise_for_status() print(f"Subclient '{subclient_name}' added successfully!") if __name__ == "__main__": add_subclient()