NDIT Cohesity Scripts
-------------------------
These scripts factilitate the automation of NDIT's data protection program with Cohesity. Theses scripts are designed to be used by authorized North Dakota State NDIT personnel only.  

Contents
--------
* classes/cohesityAPI.py 
    * Defines functions that have been tested and setup in accordance with NDIT Cohesity operating guidelines.

* classes/serviceNowAPI.py
    * Defines functions used for opening and assigning tickets for Cohesity issues

* classes/sharePointAPI.py
    * Defines functions used for looking up assets in the sharepoint configuration management database (CMDB)

* cancelJobs.py
    * Used for mass cancellation of all currently running jobs, typically used for vCenter maintenance.

* dailyErrors.py
    * Pulls all protection job runs for the previous 24 hours and creates ServiceNow tickets for any jobs in a Failure state
    * Sends an email summary to the backup teams for all job states on a daily basis.

* dailyProtectionReview.py
    * Retrieves all VM objects from vCenter sources that are registerd to Cohesity and verifies that each object is protected or exempted in accordance with NDIT procedures.
    * Reviews all protection jobs to ensure empty jobs are paused so they don't generate erroneous errors as well as ensures all popultated jobs are running.
    * Creates SerivceNow Incidents for:
        * Unprotected VMs
        * Unprotected AppNames
        * Populated Jobs that are paused

* findDuplicates.py
    * Pulls all backup jobs per vCenter and determines if a VM is listed in more than one group.

* pauseOrResumeJob.py
    * Used to mass pause or resume protectiong jobs, typically used for vCenter maintenance.

* sqlServerRegistration.py
    * Determines if the VM that identified by '-s' has been setup as a SQL server source, if not register it as one and add it to the appropriate SQL server protection group provided by CMDB lookup or specified by '-p'. 
    * Pull all kSQL object types within Cohesity and ensure the ITD-COHESITY-DBA group has access to all objects.

* updateProtectionGroupTags.py
    * Used to include or exclude vmWare protection job tags across a vCenter or individual job.

* beta/getSQLSourceErrorMessages.py
    * Pulls any failed health check information on SQL servers that could prevent the SQL server from getting backed up
    * Attempts to refresh the source to eliminate false positives
    * Opens a ServiceNow ticket if refreshing the source does not resolve the issue.

ToDo
----
* dailyProtectionReview.py
    * BUG: 
    
    * RFE:
        * SeriveNow CMDB lookups will need to be used for AppName and exemnptions, see RFE 001 & RFE 002 sections in the script

* dailyErrors.py
    * RFE:
        * Determine wheter or not we need to open tickets for jobs in a warning state.

* findDuplicates.py
    * RFE:
        * Determine if this script needs to be ran on a routine basis.
        * Add functionality to open tickets on duplicates

* updateProtectionGroupTags.py
    * RFE: 
        * Update API calls to use class calls instead of GetFilteredRequest()
        * Update tag lookup section to use the function in the class instead of the local function in the script

* sqlServerRegistration.py
    * RFE: 
        * SeriveNow CMDB lookups will need to be used for AppName and exemnptions, see RFE 001 & RFE 002 sections in the script
        * Update API calls to use class calls instead of GetFilteredRequest()

Example Python Script
---------------------
```
import json
import sys
import certifi
import urllib3

from datetime import date, timedelta

sys.path.insert(0, './classes/')
import cohesityAPI as cohesity

try: 

    # Define create and instantiate the API for a Cohesity cluster
    mdn = cohesity.API('itdmdndpc01.nd.gov')

    # Get the Auth Token and add it to the API header calls
    mdnToken = mdn.GetAuthToken()
    mdn.UpdateHeaders(mdnToken['accessToken'])

    # Get a list of objects from an API call, for a full listing of API calls, see developer.cohesity.com
    vms = mdn.GetFilteredRequest("/public/protectionSources/virtualMachines", "?protected=true")

    # Print out an indented copy of the JSON data; use jsonparser.org or notepad++ to make it easier to read
    print(json.dumps(vms, indent=4))

    # Do something with the data based on the JSON output 
    for vm in vms:
        print(vm['name'])

except OSError as cohesityError:
    print('Cohesity Error: ' + cohesityError)
```
