Code Monkey home page Code Monkey logo

opsmtools's Introduction

opsmtools

opsmtools exposes the MongoDB Ops Manager API endpoints through a simple command line script with minimal dependencies.

not all endpoint are supported yet, please contribute.

Supported Endpoints

  • Getting Hosts
  • COMING SOON: Getting host metrics
  • Getting Alerts
  • Getting Alert Configurations
  • Deleting Alert Configurations
  • Migrating Alert Configuration from one Ops Mgr to another Ops Mgr instance
  • Getting clusters
  • Listing snapshots from a clusters backups
  • Downloading a particular snapshot or just the 'latest'
  • Downloading point-in-time backup
  • Restoring backups: download and deploy any backup to another MongoDB instance

Installation

You need to have a version of Python installed in order to use mtools. Python 2.6.x (you will need to install argparse and requests) and Python 2.7.x are currently supported. To check your Python version, run python --version on the command line. Python 3.x is currently not supported.

opsmtools Installation

Installation from source

The easiest way to install opsmtools is with curl:

$curl -OL https://raw.githubusercontent.com/jasonmimick/opsmtools/master/opsmtools.py
$chmod +x opsmtools.py

Or you can use your favorite method to download the single python file.

Usage

usage: opsmtools.py [-h] --host HOST --group GROUP --username USERNAME
                    --apikey APIKEY [--getClusters] [--getHosts] [--getAlerts]
                    [--getAlertConfigs] [--deleteAlertConfigs]
                    [--postAlertConfigs] [--migrateAlertConfigs]
                    [--getSnapshots] [--createRestore] [--createRestoreLatest]
                    [--createRestoreAndDeploy] [--targetHost TARGETHOST]
                    [--targetGroup TARGETGROUP]
                    [--targetUsername TARGETUSERNAME]
                    [--targetApikey TARGETAPIKEY]
                    [--targetPassword TARGETPASSWORD]
                    [--targetAuthenticationDatabase TARGETAUTHENTICATIONDATABASE]
                    [--targetAuthenticationMechanism TARGETAUTHENTICATIONMECHANISM]
                    [--alertConfigsSource ALERTCONFIGSSOURCE]
                    [--clusterId CLUSTERID] [--snapshotId SNAPSHOTID]
                    [--snapshotTimestamp SNAPSHOTTIMESTAMP]
                    [--snapshotIncrement SNAPSHOTINCREMENT]
                    [--restoreNamespace RESTORENAMESPACE]
                    [--outDirectory OUTDIRECTORY]
                    [--restoreAndDeployTempPort RESTOREANDDEPLOYTEMPPORT]
                    [--restoreAndDeployTempMongodArgs RESTOREANDDEPLOYTEMPMONGODARGS]
                    [--restoreAndDeployDropFromTarget] [--continueOnError]
                    [--verbose]

Get alerts from MongoDB Ops/Cloud Manager

optional arguments:
  -h, --help            show this help message and exit
  --getClusters         get cluster information
  --getHosts            get host information
  --getAlerts           get alerts
  --getAlertConfigs     get alert configurations
  --deleteAlertConfigs  delete ALL alert configs from host
  --postAlertConfigs    post ALL alert configs to host
  --migrateAlertConfigs
                        migrate ALL alert configs from host to target
  --getSnapshots        get list of snapshots for a given --clusterId
  --createRestore       create a restore job from a given --clusterId for a
                        given --snapshotId
  --createRestoreLatest
                        create a restore job for the lastest snapshotId
  --createRestoreAndDeploy
                        create a restore job from a given --clusterId for a
                        given --snapshotId (or --snapshotTimestamp,
                        --snapshotIncrement is optional), download and unpack
                        it, then deploy data in --restoreNamespace to
                        --targetHost NOTE: you must have the same or higher
                        version of Mongo binaries installed on the machine
                        running this script as running on the --targetHost!
  --targetHost TARGETHOST
                        target OpsMgr/MongoDB host with protocol and port
  --targetGroup TARGETGROUP
                        target OpsMgr group id
  --targetUsername TARGETUSERNAME
                        target OpsMgr/MongoDB host user name
  --targetApikey TARGETAPIKEY
                        target OpsMgr api key for target user
  --targetPassword TARGETPASSWORD
                        target MongoDB instance password for target user
  --targetAuthenticationDatabase TARGETAUTHENTICATIONDATABASE
                        target MongoDB instance authentication database target
                        user
  --targetAuthenticationMechanism TARGETAUTHENTICATIONMECHANISM
                        target MongoDB instance authentication mechanism
                        target user
  --alertConfigsSource ALERTCONFIGSSOURCE
                        A file containing JSON alert configs or "-" for STDIN
  --clusterId CLUSTERID
                        id of replica set or sharded cluster for snapshots
  --snapshotId SNAPSHOTID
                        id of a snapshot to restore
  --snapshotTimestamp SNAPSHOTTIMESTAMP
                        point-in-time restore timestamp, format
                        2014-07-09T09:20:00Z
  --snapshotIncrement SNAPSHOTINCREMENT
                        point-in-time restore increment, a positive integer
  --restoreNamespace RESTORENAMESPACE
                        Namespace(s) to restore from snapshot. Use "*" for all
                        databases. Use "foo.*" for all collections in the foo
                        database. Use "foo.bar" for just the bar collection in
                        the foo database.
  --outDirectory OUTDIRECTORY
                        optional directory to save downloaded snapshot
  --restoreAndDeployTempPort RESTOREANDDEPLOYTEMPPORT
                        optional port number to run temporary mongod to
                        restore snapshot from, default is 27229
  --restoreAndDeployTempMongodArgs RESTOREANDDEPLOYTEMPMONGODARGS
                        optional arguments for temp mongod to restore snapshot
                        from.
  --restoreAndDeployDropFromTarget
                        optional arguments for mongorestore process used to
                        restore snapshot to --targetHost. For example "--drop"
                        to force a drop of the collection(s) to be restored.
  --continueOnError     for operations that issue multiple API calls, set this
                        flag to fail to report errors but keep going
  --verbose             enable versbose output for troubleshooting

required named arguments:
  --host HOST           the OpsMgr host with protocol and port, e.g.
                        http://server.com:8080
  --group GROUP         the OpsMgr group id
  --username USERNAME   OpsMgr user name
  --apikey APIKEY       OpsMgr api key for the user

Optional dependencies

Use pip to install terminaltables to get nice ascii tables when calling --getAlerts and other operations.

Examples

If you are getting errors, remember to add the --verbose flag to your command for useful debugging information.

Example 1: Get alerts.

$./opsmtools.py --host http://my.opsmgr.server:8080 \
               --group 57598b14e4b01b9f37aadaf8 \
               --username [email protected] --apikey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
               --getAlerts --format table
+Alerts from http://my.opsmgr.server:8080--------------------------------+
| eventTypeName         | status | created              | replicaSetName |
+-----------------------+--------+----------------------+----------------+
| MONITORING_AGENT_DOWN | CLOSED | 2016-06-13T17:34:21Z |                |
+-----------------------+--------+----------------------+----------------+
|                       |        | Number alerts        | 4              |
+-----------------------+--------+----------------------+----------------+

Example 2: Restore a backup from Ops Manager to another MongoDB instance:

./opsmtools.py --host http://ec2-127-0-0-1.compute-1.amazonaws.com:8080 \
               --group 57598b14e4b01b9f37aadaf8 \
               --username [email protected] --apikey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
               --clusterId 575ec8aee4b0fc4aec781dfb --outDirectory ~/work/dbdump/ \
               --snapshotTimestamp 2016-06-13T15:15:48Z \
               --targetHost ec2-127-0-0-91.compute-1.amazonaws.com:27102 \
               --restoreNamespace test.foo \
               --restoreAndDeployTempPort 29299 \
               --restoreAndDeployDropFromTarget \
               --createRestoreAndDeploy

Credits

opsmtools was inspired by (and borrows heavily from) the excellent mtools suite. Thanks, Thomas!

Disclaimer

This software is not supported by MongoDB, Inc. under any of their commercial support subscriptions or otherwise. Any usage of opsmtools is at your own risk. Bug reports, feature requests and questions can be posted in the Issues section here on github.

Author: [email protected]

opsmtools's People

Contributors

jasonmimick avatar rahuldhodapkar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opsmtools's Issues

Getsnaphot and download the snapshot restore files

Hello Jasonmimick,

I am trying to use your source code to get latest backup snapshot and download the restore snapshot files.

I have run script likewise as below ...

C:\Python27\Scripts>opsmtools.py --host https://XXX-zhns077.XX.xxxx.xxx:8443 --group xxxxxxfb7789472834cc91a0 --username [email protected] --apikey xxxxxx35-2da3-43bf-8507-789ddc667e05 --clusterId xxxx5477894706343f7ef7 --getSnapshots
Traceback (most recent call last):
File "C:\Python27\Scripts\opsmtools.py", line 727, in
parsed_args.action(parsed_args)
File "C:\Python27\Scripts\opsmtools.py", line 35, in get_snapshots
,auth=HTTPDigestAuth(args.username,args.apikey))
File "C:\Python27\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='xxx-xxxxx.xxx.xxxx.xxx', port=8443): Max retries exceeded with url: /api/public/v1.0/groups/xxxxxfb7789472834cc91a0/clusters/xxxxxx5477894706343f7ef7/snapshots (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)'),))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.