Forked from keithmccammon/cb-response-delete-file.py
Last active
June 17, 2016 03:42
-
-
Save jgarman/af8164e51c5aa24ced68112ce95ac247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Given a sensor ID and a file path, delete the file. This performs no logging | |
and returns no status. It is generally unhelpful and not a template upon which | |
you want to build. But if the file is present and not locked it will be | |
destroyed :) | |
""" | |
import argparse | |
import sys | |
from cbapi.response import CbEnterpriseResponseAPI | |
from cbapi.response.models import Sensor | |
from cbapi.response.live_response_api import LiveResponseError | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--profile", type=str, action="store", | |
help="The credentials.response profile to use.") | |
parser.add_argument("sensorid", type=int, action="store", | |
help="The sensor to which we should connect.") | |
parser.add_argument("filepath", type=str, action="store", | |
help="The file to delete.") | |
args = parser.parse_args() | |
if args.profile: | |
cb = CbEnterpriseResponseAPI(profile=args.profile) | |
else: | |
cb = CbEnterpriseResponseAPI() | |
sensor = cb.select(Sensor, args.sensorid) | |
with sensor.lr_session() as lr: | |
try: | |
lr.delete_file(args.filepath) | |
except LiveResponseError as e: | |
print("Error encountered deleting the file {0} from hostname {1} (sensor id {2}):".format(args.filepath, sensor.hostname, args.sensorid)) | |
print(" " + str(e)) | |
return 1 | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment