pypertrail

pypi travis doc pyup

Python wrapper library and CLI for papertrail API.

Installation

Install using pip:

$ pip install pypertrail

Requirements

  • Python 2.6, 2.7, 3.3, 3.4, or 3.5
  • A Papertrail account

Library

Accounts

import os
from pypertrail.accounts import Account

accounts = Account(os.environ['PAPERTRAIL_API_TOKEN'])

# List account usage
accounts.list()

Archives

import os
from pypertrail.archives import Archive

archives = Archive(os.environ['PAPERTRAIL_API_TOKEN'])

# List archive information
archives.list()

Groups

import os
from pypertrail.groups import Group

groups = Group(os.environ['PAPERTRAIL_API_TOKEN'])

# List groups
groups.list()

# Show a group
groups.show(group_id)

# Update a group
groups.update(group_id)

# Delete a group
groups.delete(group_id)

Saved searches

import os
from pypertrail.saved_searches import SavedSearch

saved_searches = SavedSearch(os.environ['PAPERTRAIL_API_TOKEN'])

# List saved_searches
saved_searches.list()

# Show a saved search
saved_searches.show(saved_search_id)

# Create a saved search
payload = {'name':'my_query', 'query':'sshd'}
saved_searches.create(payload)

# Update a saved search
payload = {'search[query]':'another_query'}
saved_searches.update(payload)

# Delete a saved search
saved_searches.delete(saved_search_id)

Systems

import os
from pypertrail.systems import System

systems = Search(os.environ['PAPERTRAIL_API_TOKEN'])

# List systems
systems.list()

# Show a system
systems.show(system_id)

# Create a system
payload = {'system[name]':'foo', 'system[hostname]':'bar', 'destination_port':46865}
systems.create(payload)

# Update a system
payload = {'system[name]':'another_name'}
systems.update(system_id, payload)

# Delete a system
systems.delete(system_id)

# Join a group
payload = {'group_id':10}
systems.join_group(system_id, payload)

# Leave a group
payload = {'group_id':10}
systems.leave_group(system_id, payload)

Users

import os
from pypertrail.users import User

users = User(os.environ['PAPERTRAIL_API_TOKEN'])

# List users
users.list()

# Invite a user
payload = {'email':'contact@quent.in', 'read_only':'true'}
users.invite(payload)

# Delete a user
users.delete(user_id)

CLI

CLI Authentication

Via environment variables:

$ export PAPERTRAIL_API_TOKEN=my_token
$ pypertrail users list

Via implicit ~/.pypertrail.yml:

$ echo "token: my_token" > ~/.pypertrail.yml
$ pypertrail users list

Via (–conf/-c) option:

$ echo "token: my_token" > /path/to/config
$ pypertrail --conf /path/to/config users list

Via (–token/-t) option:

$ pypertrail --token my_token users list

Subcommands

Accounts

Examples:

$ pypertrail --pretty accounts list

Archives

Examples:

$ pypertrail --pretty archives list

Saved searches

Examples:

$ pypertrail saved_searches create --payload '{"search[name]":"foo", "search[query]":"bar"}'
$ pypertrail saved_searches delete 1
$ pypertrail saved_searches list
$ pypertrail saved_searches show 1
$ pypertrail saved_searches update 1 --payload '{"search[query]":"another_query"}'

Groups

Examples:

$ pypertrail groups delete 1
$ pypertrail groups list
$ pypertrail groups show 1
$ pypertrail groups update 1 --payload '{"group[name]":"another_name"}'

Search

Examples:

$ pypertrail search events
$ pypertrail search events --follow
$ pypertrail search events --follow --color program
$ pypertrail search events --follow --query sshd
$ pypertrail search events --follow --json

Systems

Examples:

$ pypertrail systems create --payload '{"system[name]":"foo", "system[hostname]":"bar", "destination_port":46865}'
$ pypertrail systems delete 1
$ pypertrail systems join_group 1 --payload '{"group_id":10}'
$ pypertrail systems leave_group 1 --payload '{"group_id":10}'
$ pypertrail systems list
$ pypertrail systems show 1
$ pypertrail systems update 1 --payload '{"system[name]":"another_name"}'

Users

Examples:

$ pypertrail users delete 1
$ pypertrail users invite --payload '{"email":"contact@quent.in", "read_only":true}'
$ pypertrail users list

History

View the changelog

License