Minimalistic MMS API agent for ruby
gem install mms-api
The MMS Public API follows the principles of the REST architectural style to expose a number of internal resources which enable programmatic access to MMS’s features. Current implementation support only a few of API features.
Resource | Get All | Get One | Create | Update | Delete |
---|---|---|---|---|---|
Groups | + | + | |||
Hosts | + | + | |||
Clusters | + | + | |||
Snapshots | + | + | |||
Alerts | + | + | |||
Restore Jobs | + | + | + |
Source code itself is well-documented so when writing code it should auto-complete and hint in all supported usages.
Most important part of the api is client. In order to make any request you need to instantiate client with correct params.
client = MMS::Client.new('username', 'api_key')
This client is used by all other classes connecting to api no matter if it's Resource or helper class like Agent.
Agent is simple wrapper class for listing all accessible resources.
client = MMS::Client.new('username', 'api_key')
agent = MMS::Agent.new(client)
agent.alerts.each do |alert|
alert.ack('now')
end
List of resource-listing agent methods:
- groups
- hosts
- clusters
- snapshots
- alerts
- restorejobs
You can find lists of resource by using agent as pointed above, or by various resource methods. Each resource have a find method loading certain resource with provided id (plus corresponding parent ids), e.g.
client = new MMS::Client.new('username', 'api_key')
host = MMS::Resource::Host.find(client, 'group_id', 'host_id')
Additionally some resources have additional instance methods to retrieve sub-resources, e.g.
client = new MMS::Client.new('username', 'api_key')
group = MMS::Resource::Group.find(client, 'group_id')
hosts = group.hosts
There is a built-in cli with several commands retrieving api resource lists.
Cli uses configuration with all values set to default ones.
Config itself has config_file
property which merges itself with params from the file.
By default config_file
points to home directory, but it can be changed to points to any file.
[email protected]
apikey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
apiurl=https://mms.mydomain.tld/api/public/v1.0
default_group_id=your-group-id
default_cluster_id=your-cluster-id
Additionally some options can be modified using cli options.
$ mms-api --help
Usage:
[OPTIONS] SUBCOMMAND [ARG] ...
Parameters:
SUBCOMMAND subcommand
[ARG] ... subcommand arguments
Subcommands:
groups Groups
hosts Hosts
clusters Clusters
alerts Alerts
snapshots Snapshots
restorejobs Restorejobs
Options:
-h, --help print help
-u, --username <string> MMS user
-k, --apikey <string> MMS api-key
-a, --apiurl <string> MMS api url. Full url including version: https://mms.mydomain.tld/api/public/v1.0
-v, --version Version
-g, --default-group-id <string> Default MMS group id
-c, --default-cluster-id <string> Default MMS cluster id
--cfg <string> Config file path
-i, --ignore Ignore flag of --group-id and -cluster-id (default: false)
-j, --json Print JSON output (default: false)
-l, --limit <integer> Limit for result items