Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pushbullet notification support to ZED #3327

Closed
wants to merge 5 commits into from
Closed

Add Pushbullet notification support to ZED #3327

wants to merge 5 commits into from

Conversation

dun
Copy link
Contributor

@dun dun commented Apr 21, 2015

I was playing with Pushbullet recently and thought this would be great for ZED notifications. It supports several clients and has an open API.

This patch stack begins with cleaning up the existing ZEDLETs, refactoring common code blocks into zed-functions.sh, adopting a more consistent coding style, updating exit codes, etc. All scripts now run cleanly through ShellCheck.

The old "email" ZEDLETs are replaced with new "notify" ZEDLETs. A notification can now be sent via email and/or Pushbullet. Additional notification methods will likely be added in the future.

Pushbullet notifications are enabled by setting ZED_PUSHBULLET_ACCESS_TOKEN and (optionally) ZED_PUSHBULLET_CHANNEL_TAG in zed.rc. The Pushbullet implementation requires awk, curl, and sed executables to be installed in the standard PATH.

zed pb1 checksum
zed pb2 spare
zed pb3 resilver

dun added 5 commits April 21, 2015 00:02
This commit factors out several common ZEDLET code blocks into
zed-functions.sh.  This shortens the length of the scripts, thereby
(hopefully) making them easier to understand and maintain.

In addition, this commit revamps the coding style used by the
scripts to be more consistent and (again, hopefully) maintainable.
It now mostly follows the Google Shell Style Guide.  I've tried to
assimilate the following resources:

  Google Shell Style Guide
  https://google-styleguide.googlecode.com/svn/trunk/shell.xml

  Dash as /bin/sh
  https://wiki.ubuntu.com/DashAsBinSh

  Filenames and Pathnames in Shell: How to do it Correctly
  http://www.dwheeler.com/essays/filenames-in-shell.html

  Common shell script mistakes
  http://www.pixelbeat.org/programming/shell_script_mistakes.html

Finally, this commit updates the exit codes used by the ZEDLETs to be
more consistent with one another.

All scripts run cleanly through ShellCheck <http://www.shellcheck.net/>.
All scripts have been tested on bash and dash.

Signed-off-by: Chris Dunlap <[email protected]>
Several ZEDLETs already exist for sending email in reponse to a
particular zevent.  While email is ubiquitous, alternative methods may
be better suited for some configurations.  Instead of duplicating the
"email" ZEDLETs for every future notification method, it is preferable
to abstract the notification method into a function.  This has the
added benefit of reducing the amount of code duplicated between
ZEDLETs, and allowing related bugs to be fixed in a single location.

This commit replaces the existing "email" ZEDLETs with corresponding
"notify" ZEDLETs.  In addition, the ZEDLET code for sending an
email message has been moved into the zed_notify_email() function.
And this zed_notify_email() has been added to a generic zed_notify()
function for sending notifications via all available methods that
have been configured.

This commit also changes a couple of related zed.rc variables.
ZED_EMAIL_INTERVAL_SECS is changed to ZED_NOTIFY_INTERVAL_SECS,
and ZED_EMAIL_VERBOSE is changed to ZED_NOTIFY_VERBOSE.  Note that
ZED_EMAIL remains unchanged as its use is solely for the email
notification method.

Signed-off-by: Chris Dunlap <[email protected]>
This commit adds the zed_notify_pushbullet() function and hooks
it into zed_notify(), thereby integrating it with the existing
"notify" ZEDLETs.  This enables ZED to push notifications to your
desktop computer and/or mobile device(s).  It is configured with the
ZED_PUSHBULLET_ACCESS_TOKEN and ZED_PUSHBULLET_CHANNEL_TAG variables
in zed.rc.

  https://www.pushbullet.com/

The Makefile install-data-local target has been replaced with
install-data-hook.  With the "-local" target, there is no particular
guarantee of execution order.  But with the zed.rc now potentially
containing sensitive information (i.e., the Pushbullet access token),
the recommended permissions have changed to 0600.  The "-hook" target
is always executed after the main rule's work is done; thus, the
chmod will always take place after the zed.rc file has been installed.

  https://www.gnu.org/software/automake/manual/automake.html#Extending

Signed-off-by: Chris Dunlap <[email protected]>
The io-spare.sh ZEDLET does not generate a notification when a failing
device is replaced with a hot spare.  Maybe it should tell someone.

This commit adds a notification message to the io-spare.sh ZEDLET.
This notification is triggered when a failing device is successfully
replaced with a hot spare after encountering a checksum or io error.

Signed-off-by: Chris Dunlap <[email protected]>
The data-notify.sh ZEDLET serves a very similar purpose to
io-notify.sh, namely, to generate a notification in response to a
particular error event.  Initially, data-notify.sh was separated from
io-notify.sh since the "data" zevent does not (as I understand it)
pertain to a specific vdev device.  This stands in contrast to the
"checksum" and "io" zevents (both handled by io-notify.sh) that can
be attributed to a specific vdev.  At the time, it seemed simpler to
handle these two cases in separate scripts.

This commit adds support for the "data" zevent to io-notify.sh, and
symlinks io-notify.sh to data-notify.sh.  It also adds the counts
for vdev_read_errors, vdev_write_errors, and vdev_cksum_errors to
the notification message.

Signed-off-by: Chris Dunlap <[email protected]>
@FransUrbo
Copy link
Contributor

My stuff is to old :(. Need iOS 7.1 (I have 6.1.3) and OSX 10.9 (I have 10.7.5). At least the Safari client seems to be working.

Trying this, by offline and then online a disk in the pool, I get the resilver finished via email, but NOT (that I can see) in Pushbullet…

Trying to reconstruct what this do (by adding some debugging messages), I came up with this:

curl -u "<my token>:" -X POST "https://api.pushbullet.com/v2/pushes" --header "Content-Type: application/json" \
    --data-binary "{'channel_tag': '<my tag>', 'type': 'note', 'title': 'test', 'body': 'testtest'}"

That gave me:

{"error":{"type":"invalid_request","message":"Failed to decode JSON body.","cat":"(=^###=)"}}

@FransUrbo
Copy link
Contributor

Removing the extra ':' in the token string, I get:

Enter host password for user '<my token>':

@FransUrbo
Copy link
Contributor

Never mind. Don't know if it was all my tests or 'kicking' pushbullet that eventually made it work. But it works…

Although, there's no tabbing etc in the notify. Is that a limitation on pushbullet?

@behlendorf
Copy link
Contributor

Although, there's no tabbing etc in the notify. Is that a limitation on pushbullet?

Yes, I believe push bullet strips it.

@behlendorf
Copy link
Contributor

@dun nice work! This looks really nice. I've merged this branch to master after doing some basic functional testing. In the process I fixed the minor nit a mentioned about the README by adding it as an EXTRA_DIST.

While this is definitely a step in the right direction it may be somewhat disruptive. Let's keep a close eye on the tracker for the next few months for for any new issues/regressions this may have accidentally introduced.

52d5a1c Merge branch 'zed-pushbullet'
ce119da Combine data-notify.sh with io-notify.sh
090b191 Add notification to io-spare.sh
a0d065f Add support for Pushbullet notifications
20967ff Replace "email" ZEDLETs with "notify" ZEDLETs
aded9a6 Cleanup ZEDLETs

@behlendorf behlendorf added this to the 0.6.5 milestone Apr 27, 2015
@behlendorf behlendorf added Type: Feature Feature request or new feature Difficulty - Medium labels Apr 27, 2015
@dun
Copy link
Contributor Author

dun commented Apr 28, 2015

@FransUrbo Re: tabbing. You can embed tabs in the notification message with a "\t" character sequence. But the web interface removes leading whitespace when displaying notifications, whereas the Android app appears to use a tab stop of 3 spaces. I don't have anything with which to test the iOS app.

@dun dun deleted the zed-pushbullet branch October 9, 2015 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Feature request or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants