Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanballs committed Jul 4, 2016
0 parents commit 3d08264
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.pyc
dist/
cabot_check_skeleton.egg-info/
*.sw?
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2014 Arachnys Information Services Ltd and individual contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Cabot ICMP Check Plugin
=====

This is a skeleton status check plugin for Cabot.
Empty file.
49 changes: 49 additions & 0 deletions cabot_check_skeleton/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from django.conf import settings
from django.template import Context, Template
from django import forms
from cabot.plugins.models import StatusCheckPlugin
from cabot.cabotapp.models import StatusCheckResult
from os import environ as env
import logging
import requests
from django.utils import timezone


class SkeletonStatusCheckForm(forms.Form):
bone_name = forms.CharField(
help_text = 'Name of the bone to check',
)


class SkeletonStatusCheckPlugin(StatusCheckPlugin):
name = 'SkeletonStatusCheckPlugin'
slug = 'cabot_check_skeleton'
author = 'Jonathan Balls'
version = '0.0.1'
font_icon = 'glyphicon glyphicon-skull'

config_form = SkeletonStatusCheckForm

plugin_variables = [
'SKELETON_LIST_OF_BONES',
]

def run(self, check, result):

list_of_bones = env.get('SKELETON_LIST_OF_BONES', None)

if not list_of_bones:
result.succeeded = False
result.error = u'SKELETON_LIST_OF_BONES is not defined in environment variables'
return result

list_of_bones = list_of_bones.split(',')

if check.bone_name in list_of_bones:
result.succeeded = True
return result
else:
result.succeeded = False
result.error = u'%s is not in the list of bones' % check.bone_name
return result

42 changes: 42 additions & 0 deletions cabot_check_skeleton/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django.contrib.auth.models import User
from cabot.cabotapp.tests.tests_basic import LocalTestCase
from cabot.cabotapp.models import StatusCheck, Instance
from cabot.plugins.models import StatusCheckPluginModel
import cabot_check_icmp.plugin

class TestICMPStatusCheckPlugin(LocalTestCase):

def setUp(self):
super(TestICMPStatusCheckPlugin, self).setUp()

self.icmp_check_plugin, created = StatusCheckPluginModel.objects.get_or_create(
slug='cabot_check_icmp'
)

self.icmp_check = StatusCheck.objects.create(
check_plugin=self.icmp_check_plugin,
name = 'Default ICMP Check'
)

self.instance = Instance.objects.create(
name = 'Default Instance',
address = 'localhost'
)

self.instance.status_checks.add(self.icmp_check)
self.instance.save()

# We aren't mocking subprocess.Popen because it's more hassle than its
# worth. The below functions should work absolutely fine.
def test_run_success(self):
self.instance.address = 'localhost' # Always pingable
self.instance.save()
result = self.icmp_check.run()
self.assertTrue(result.succeeded)

def test_run_failure(self):
self.instance.address = '256.256.256.256' # Impossible IP
self.instance.save()
result = self.icmp_check.run()
self.assertFalse(result.succeeded)

2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python

from setuptools import setup, find_packages

setup(name='cabot-check-skeleton',
version='0.0.1',
description='A skeleton check plugin for Cabot by Arachnys',
author='Arachnys',
author_email='[email protected]',
url='http://cabotapp.com',
packages=find_packages(),
download_url= 'https://github.com/cabotapp/cabot-check-skeleton',
)

0 comments on commit 3d08264

Please sign in to comment.