Skip to content
This repository has been archived by the owner on Nov 9, 2018. It is now read-only.

Commit

Permalink
Pushover support (#10)
Browse files Browse the repository at this point in the history
* Pushover support

* Update documentation to include setting up Pushover
  • Loading branch information
helpsterTee authored and errbufferoverfl committed Oct 8, 2017
1 parent 96a88f4 commit 7b4fda2
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 6 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

USB Canary is a Linux and OSX tool that uses psutil to monitor USB devices
either around the clock, or just while your computer is locked. It can
be configured to send you an SMS via the Twilio API, or notify a Slack
channel with it's inbuilt Slack bot.
be configured to send you an SMS via the Twilio API, notify a Slack
channel with it's inbuilt Slack bot, or send a push message through Pushover.

## Getting Started

Expand All @@ -19,6 +19,7 @@ basic client for Slack.com, which can optionally connect to the Slack
Real Time Messaging (RTM) API.
- [twilio](https://github.com/twilio/twilio-python) - A Python module
for communicating with the Twilio API and generating TwiML.
- [pushover](https://github.com/Thibauth/python-pushover) - Comprehensive bindings and command line utility for the Pushover notification service
- [psutil](https://pypi.python.org/pypi/psutil) - Cross-platform lib
for process and system monitoring in Python.
- [gcc](https://gcc.gnu.org/) - GNU Compiler Collection
Expand Down Expand Up @@ -74,6 +75,7 @@ use `pip` with `sudo`. You can install the packages as follows:
```
pip install slackclient==1.0.9
pip install twilio==5.7.0
pip install python-pushover==0.3
pip install psutil==5.3.1
pip install sander-daemon==1.0.0
```
Expand All @@ -100,11 +102,17 @@ An example `settings.json` file:
"twilio_number": "+61491570156",
"mobile_number": "+61491570157"
},
"pushover": {
"priority": 1,
"user_key": "youruserkeygoeshere",
"api_token": "yourapitokengoeshere"
},
"general": {
"paranoid": true,
"screensaver": "xscreensaver",
"slack": false,
"twilio": true,
"pushover": false,
}
}
}
Expand All @@ -124,13 +132,13 @@ just checking which packages are installed via the `apt` library, if
both of them are installed though, it will leave you to determine which
one you are using - if you have an unsupported screensaver, don't fret,
you can still run it in paranoid mode.

Paranoid mode is also suitable for people who want to monitor if their
servers have had USB's plugged into them,
although I haven't tested them on Linode, Amazon Web Services, or
Digital Ocean it is suitable for those with
physical servers that may need this sort of monitoring.

To start the application:
```shell
# Linux users
Expand Down Expand Up @@ -159,6 +167,10 @@ To use the Twilio integration you will need to get an:

To use the Slack integration you will need to [setup a bot user](https://api.slack.com/bot-users)

### Pushover

To use Pushover API for sending push messages to your devices, you need to create an [account and application](https://pushover.net/faq#overview-what)

## Exit Codes

| Exit Code | Reason | Solution |
Expand All @@ -176,6 +188,10 @@ To use the Slack integration you will need to [setup a bot user](https://api.sla
| 409 | Receiving mobile # is blank | Twilio receiving mobile number has not been set, check `settings.json` |
| 410 | Twilio mobile # is blank | Twilio allocated mobile number has not been set, check `settings.json` |
| 411 | Twilio key missing in settings.json | Twilio JSON block is not in settings file, check `settings.json` |
| 412 | Pushover user key missing in settings.json | Pushover user key (per account) is missing, check `settings.json` |
| 413 | Pushover user key missing in settings.json | Pushover api key (per registered app) is missing, check `settings.json` |
| 414 | Pushover priority level missing in settings.json | Pushover priority level is missing, check `settings.json` |
| 415 | Pushover key missing in settings.json | Pushover JSON block is not in settings file, check `settings.json` |
| 501 | `settings.json` file missing. | Download setting.json from Github |
| 502 | Unable to parse settings.json | Check for erroneous symbols, use [JSONLint](http://jsonlint.com/) to check formatting |
| 503 | Paranoid option not set correctly. | Paranoid option not set, or set incorrectly |
Expand Down
11 changes: 11 additions & 0 deletions canary/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from canary.slack.slack import load_slack_settings
from canary.twilleo.twilleo import load_twilio_settings

from canary.pushovr.pushover import load_pushover_settings
from pushover import Client


def send_message(alert):
logging.debug('Opening settings.json.')
Expand All @@ -33,6 +36,8 @@ def send_message(alert):
twilio_enabled = settings_file['settings']['general']['twilio']
logging.debug('Getting Slack settings.')
slack_enabled = settings_file['settings']['general']['slack']
logging.debug('Getting Pushover settings.')
pushover_enabled = settings_file['settings']['general']['pushover']

logging.debug('Checking if Twilio is enabled.')
if twilio_enabled:
Expand All @@ -56,3 +61,9 @@ def send_message(alert):
slack_settings = load_slack_settings()
logging.debug('Staring up Slack Bot.')
slack_bot.run_bot(alert, slack_settings['channel_name'])
logging.debug('Checking if Pushover is enabled.')
if pushover_enabled:
logging.debug('Opening settings.json.')
pushover_settings = load_pushover_settings()
client = Client(pushover_settings['user_key'], api_token=pushover_settings['api_token'])
client.send_message(alert, priority=pushover_settings['priority'])
Empty file added canary/pushovr/__init__.py
Empty file.
48 changes: 48 additions & 0 deletions canary/pushovr/pushover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# usb_canary - a Linux tool that uses pyudev to monitor devices while
# your computer is locked. In the case it detects someone plugging in
# or unplugging devices it can be configured to make a noise or send
# you an SMS alerting to you of the potential security breach.

# Copyright (C) 2017 errbufferoverfl
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import sys

import canary.settings


def load_pushover_settings():
"""
Opens settings.json and checks all values have been set, if they have, creates a list containing these details.
If not exits and notifies user of misconfiguration
:return: list containing options to use Pushover API
"""
pushover_settings = canary.settings.open_settings()

pushover = pushover_settings['settings']['pushover']

try:
# sanity check that the user has actually supplied data
if not pushover['user_key']:
print('Pushover user key has been left blank')
sys.exit(412)
elif not pushover['api_token']:
print('Pushover API token has been left blank')
sys.exit(413)
elif not pushover['priority']:
print('Pushover message priority has been left blank')
sys.exit(414)
else:
return pushover
except KeyError:
print('Pushover key missing in the settings file')
sys.exit(415)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ psutil==5.3.1
sander-daemon==1.0.0
slackclient==1.0.9
twilio==5.7.0
python-pushover==0.3
10 changes: 8 additions & 2 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
"twilio_number": "+61491570156",
"mobile_number": "+61491570157"
},
"pushover": {
"priority": 1,
"user_key": "youruserkeygoeshere",
"api_token": "yourapitokengoeshere"
},
"general": {
"paranoid": true,
"screensaver": "xscreensaver",
"slack": false,
"twilio": true
"twilio": true,
"pushover": false,
}
}
}
}
2 changes: 2 additions & 0 deletions usbcanary.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

twilio_settings = None
slack_settings = None
pushover_settings = None

file_path = os.path.dirname(__file__)


Expand Down

0 comments on commit 7b4fda2

Please sign in to comment.