REST API to disable the CommCell Scheduler and Job Activity

Last post 06-29-2018, 1:36 AM by OzStu. 6 replies.
Sort Posts: Previous Next
  • REST API to disable the CommCell Scheduler and Job Activity
    Posted: 06-26-2018, 10:13 PM

    Hi FOlk,

     

    I've been trying to automate the steps to shutdown the CommServe for updates or DR tests, and I'm looking for a way to disable the activity for the whole CommCell.

     

    In particular, I want to disable the CommCell Scheduler (*ALL* schedules) before suspending any running jobs and doing a DR Backups, then stopping services.

     

    I've worked out how to Authenticate via REST, get a list of active jobs, and suspending them, and I can see the API for DR backups, but nothing for disabling the scheduler

     

    Oh, and I'm doing it in Powershell...... Embarassed

     

    Attachment is the activity control I am refering to :)

     

     

    Happy to share code :)


  • Re: REST API to disable the CommCell Scheduler and Job Activity
    Posted: 06-27-2018, 1:45 PM

    While I don't see a regular API call for it, this can be done through the POST /ExecuteQCommand call using this payload - even via a PowerShell call :)

    Enable CommCell activity:

    <App_SetCommCellPropertiesReq>
    <commCellInfo>
    <commCellActivityControlInfo>
    <activityControlOptions activityType="128" enableAfterADelay="0" enableActivityType="1" />
    </commCellActivityControlInfo>
    </commCellInfo>
    </App_SetCommCellPropertiesReq>

    Disable CommCell activity:

    <App_SetCommCellPropertiesReq>
    <commCellInfo>
    <commCellActivityControlInfo>
    <activityControlOptions activityType="128" enableAfterADelay="0" enableActivityType="0" />
    </commCellActivityControlInfo>
    </commCellInfo>
    </App_SetCommCellPropertiesReq>

    Cheers,
    Luke
    (@cv_skywalker)
  • Re: REST API to disable the CommCell Scheduler and Job Activity
    Posted: 06-27-2018, 7:44 PM

    That should work!

    I did have a brief look to see if I could do it with an ExecuteQCommand - is that in the doco?

    I'll give it a go and let you know.

    (Love the Bio!  Tongue out)

     

    Cheers,


    Stuart Walker

  • Re: REST API to disable the CommCell Scheduler and Job Activity
    Posted: 06-27-2018, 8:18 PM

    Hmm, except which qcommand to I give it to do that?

    (And do I have to do a qlogin (via post) before I do that, or is the token from the POST login enough?)

     

    Cheers,

    Stuart

  • Re: REST API to disable the CommCell Scheduler and Job Activity
    Posted: 06-28-2018, 3:09 AM

     

    For reference, this is the code I  have so far :)

     

    #
    # Which server are we talking to
    #
    $Server ="COMMCELL"
    $WebServer = "http://" + $Server + ":81/SearchSvc/CVWebService.svc"

    #
    # Get domain credentials with admin right sfor CommCell
    #
    if (!$Cred)
    {
    $Cred = Get-Credential -Message "Please enter full domain credentials that have admin rights to CommVault server $Server"
    }


    # Adapted from https://forum.commvault.com/forums/thread/55789.aspx

    #
    # encode the password to something that REST/CommVault can handle
    #
    $passwordB64byte = [System.Text.Encoding]::UTF8.GetBytes($cred.GetNetworkCredential().Password)
    $encodedPassword = [System.Convert]::ToBase64String($passwordB64byte)


    #
    # Set the headers for the REST command
    #
    $Headers = @{Accept = 'application/json'}

    #
    # Set the body of the REST command
    #
    $Body = @{
    username = $Cred.UserName
    password = $encodedPassword
    }


    #
    # Login to Commvault REST API
    #
    $Result = Invoke-RestMethod -Method POST -Uri "$WebServer/Login" -Headers $Headers -Body $($Body | ConvertTo-Json) -ContentType "application/json"

    #
    # Save QSDK token
    #
    $Headers["Authtoken"] = $Result.token


    #
    # Get a list of currently running jobs
    #
    $RunningJobs = Invoke-RestMethod -Method GET -Uri "$WebServer/Job?jobCategory=Active" -Headers $Headers


    #
    # Step through each job in the list and perform actions.....
    #
    foreach ($Job in $RunningJobs.jobs.jobSummary)
    {
    #
    # If it's not suspended, then suspend it (temp exemption for aux copy and DDB backups whilst testing)
    #
    if ($Job.status -ne "Suspended" -and $Job.subclientName -ne "DDBBackup" -and $Job.localizedOperationName -ne "Auxiliary Copy" )
    {
    $SuspendAttempt= Invoke-RestMethod -Method POST -Uri "$WebServer//Job/$($Job.jobId)/action/pause" -Headers $Headers
    if ($SuspendAttempt.errors.errList.errorCode -ne 0)
    {
    Write-Error "Suspend failed for Job ID: $($Job.jobId) `r`n With Error Message $($SuspendAttempt.errors.errLogMessage)"
    }

    else
    {
    Write-Host "Job ID: $($Job.jobId) suspended"
    }
    }
    else
    {
    if ($Job.status -eq "Suspended")
    {
    Write-Host "`t`t Job $($Job.jobId) is already suspended" -ForegroundColor DarkYellow
    }
    else
    {
    Write-Host "`t`t Job $($Job.jobId) is not a client backup $($Job.localizedOperationName) : $($Job.subclientName) " -ForegroundColor DarkYellow
    }
    }
    }



  • Re: REST API to disable the CommCell Scheduler and Job Activity
    Posted: 06-28-2018, 11:26 AM

    OzStu:

    Hmm, except which qcommand to I give it to do that?

    (And do I have to do a qlogin (via post) before I do that, or is the token from the POST login enough?)

    No, once you login (POST /Login), that token is your QSDK session for all commands until you either logout or the session timeouts, whichever comes first.

    Once logged in, just call POST /ExecuteQCommand, here's a quick example I hacked up:

    https://github.com/ozskywalker/oddcode/blob/master/CV-RESTAPI-QOperationExecute-DisableAllJobActivity.ps1

    For more details, have a quick look at the POSTMAN collection:

    • https://api.commvault.com/#3707251b-cc26-8c00-fb24-d007e6d8d236
    Please forgive the hackjob on the code... :)

    Cheers,
    Luke
    (@cv_skywalker)
  • Re: REST API to disable the CommCell Scheduler and Job Activity
    Posted: 06-29-2018, 1:36 AM

    WooHoo!

     

    Yep, that did it!

    so I have it logging in, disabling the scheduler, getting a list of active jobs, and pausing said jobs....

     

    Just gotta do the DR backup (shouldn't be too hard), and then work how to apply Windows updates.

The content of the forums, threads and posts reflects the thoughts and opinions of each author, and does not represent the thoughts, opinions, plans or strategies of Commvault Systems, Inc. ("Commvault") and Commvault undertakes no obligation to update, correct or modify any statements made in this forum. Any and all third party links, statements, comments, or feedback posted to, or otherwise provided by this forum, thread or post are not affiliated with, nor endorsed by, Commvault.
Commvault, Commvault and logo, the “CV” logo, Commvault Systems, Solving Forward, SIM, Singular Information Management, Simpana, Commvault Galaxy, Unified Data Management, QiNetix, Quick Recovery, QR, CommNet, GridStor, Vault Tracker, InnerVault, QuickSnap, QSnap, Recovery Director, CommServe, CommCell, SnapProtect, ROMS, and CommValue, are trademarks or registered trademarks of Commvault Systems, Inc. All other third party brands, products, service names, trademarks, or registered service marks are the property of and used to identify the products or services of their respective owners. All specifications are subject to change without notice.
Close
Copyright © 2019 Commvault | All Rights Reserved. | Legal | Privacy Policy