Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanFred committed Sep 27, 2017
0 parents commit 9bcfc31
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
.DS_Store
*.pyc
*.egg-info
build/
dist/
5 changes: 5 additions & 0 deletions CHANGES
@@ -0,0 +1,5 @@

Version 0.1.0
-------------

* Initial Version
9 changes: 9 additions & 0 deletions LICENSE
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2017 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.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -0,0 +1 @@
include README.md
10 changes: 10 additions & 0 deletions README.md
@@ -0,0 +1,10 @@
Network check for Cabot
=======================

Usage
=====

Creating a check
----------------

When creating a check, you can set a host and an port. That's about it.
Empty file added cabot_check_network/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions cabot_check_network/migrations/0001_initial.py
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-09-13 11:44
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('cabotapp', '0006_auto_20170821_1000'),
]

operations = [
migrations.CreateModel(
name='NetworkStatusCheck',
fields=[
('statuscheck_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='cabotapp.StatusCheck')),
('host', models.TextField(help_text=b'Host to check.', null=True)),
('port', models.PositiveIntegerField(help_text=b'Port to check.', null=True)),
],
options={
'abstract': False,
},
bases=('cabotapp.statuscheck',),
),
]
Empty file.
33 changes: 33 additions & 0 deletions cabot_check_network/models.py
@@ -0,0 +1,33 @@
import socket

from django.db import models

from cabot.cabotapp.models import StatusCheck, StatusCheckResult


class NetworkStatusCheck(StatusCheck):
check_name = 'network'
edit_url_name = 'update-network-check'
duplicate_url_name = 'duplicate-network-check'
icon_class = 'glyphicon-transfer'
host = models.TextField(
help_text='Host to check.',
)
port = models.PositiveIntegerField(
help_text='Port to check.',
)

def _run(self):
result = StatusCheckResult(status_check=self)

try:
s = socket.create_connection((self.host, self.port), self.timeout)
s.shutdown(socket.SHUT_RDWR)
s.close()
except Exception as e:
result.error = u'Error occurred: %s' % (e.message,)
result.succeeded = False
else:
result.succeeded = True

return result
20 changes: 20 additions & 0 deletions cabot_check_network/urls.py
@@ -0,0 +1,20 @@
from django.conf.urls import url

from .views import (NetworkCheckCreateView, NetworkCheckUpdateView,
duplicate_check)

urlpatterns = [

url(r'^networkcheck/create/',
view=NetworkCheckCreateView.as_view(),
name='create-network-check'),

url(r'^networkcheck/update/(?P<pk>\d+)/',
view=NetworkCheckUpdateView.as_view(),
name='update-network-check'),

url(r'^networkcheck/duplicate/(?P<pk>\d+)/',
view=duplicate_check,
name='duplicate-network-check')

]
50 changes: 50 additions & 0 deletions cabot_check_network/views.py
@@ -0,0 +1,50 @@
from django import forms
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from cabot.cabotapp.models import StatusCheck
from cabot.cabotapp.views import (CheckCreateView, CheckUpdateView,
StatusCheckForm, base_widgets)

from .models import NetworkStatusCheck


class NetworkStatusCheckForm(StatusCheckForm):
symmetrical_fields = ('service_set', 'instance_set')

class Meta:
model = NetworkStatusCheck
fields = (
'name',
'host',
'port',
'timeout',
'frequency',
'active',
'importance',
'debounce',
)

widgets = dict(**base_widgets)
widgets.update({
'host': forms.TextInput(attrs={
'style': 'width: 100%',
'placeholder': 'service.arachnys.com',
})
})


class NetworkCheckCreateView(CheckCreateView):
model = NetworkStatusCheck
form_class = NetworkStatusCheckForm


class NetworkCheckUpdateView(CheckUpdateView):
model = NetworkStatusCheck
form_class = NetworkStatusCheckForm


def duplicate_check(request, pk):
pc = StatusCheck.objects.get(pk=pk)
npk = pc.duplicate()
return HttpResponseRedirect(reverse('update-network-check', kwargs={'pk': npk}))
2 changes: 2 additions & 0 deletions setup.cfg
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
12 changes: 12 additions & 0 deletions setup.py
@@ -0,0 +1,12 @@
#!/usr/bin/env python

from setuptools import find_packages, setup

setup(name='cabot_check_network',
version='0.1.0',
description='A network check plugin for Cabot by Arachnys',
author='Arachnys',
author_email='techteam@arachnys.com',
url='http://cabotapp.com',
packages=find_packages(),
)

0 comments on commit 9bcfc31

Please sign in to comment.