Skip to content

Commit

Permalink
Update to 2.2.1, distro detection, update requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrusev committed Jun 9, 2015
1 parent dfd497c commit 3ac527d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 57 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
2.2.1 - 09.06.2015
==============

* Collects facts about the distro with Ansible
* Collects facts about the distro with a ported Ansible module
* Container module fixes
* Updated requirements

Expand Down
26 changes: 21 additions & 5 deletions amonagent/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
SEPARATOR = "\n{color}---------{end}\n".format(color=OKGREEN,end=ENDC)


def print_data(info=None, message=None):
if message == 'OK':
print info
print SEPARATOR

def test_checks():
# Distro information

distro = get_distro()
if len(distro) > 0:
info = get_distro()
if len(info) > 0:
message = 'OK'
color = OKGREEN
else:
message = 'Fail'
color = FAIL

print "Distro collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)
print_data(info=info, message=message)



info = get_cpu_info()
Expand All @@ -48,6 +57,7 @@ def test_checks():
color = FAIL

print "CPU Info collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)
print_data(info=info, message=message)

info = get_ip_address()
if len(info) > 0:
Expand All @@ -58,7 +68,7 @@ def test_checks():
color = FAIL

print "IP address collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)

print_data(info=info, message=message)

info = get_uptime()
if len(info) > 0:
Expand All @@ -69,6 +79,7 @@ def test_checks():
color = FAIL

print "Uptime collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)
print_data(info=info, message=message)


info = get_memory_info()
Expand All @@ -80,6 +91,7 @@ def test_checks():
color = FAIL

print "Memory collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)
print_data(info=info, message=message)


info = disk_check.check()
Expand All @@ -91,6 +103,7 @@ def test_checks():
color = FAIL

print "Disk usage collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)
print_data(info=info, message=message)


info = get_network_traffic()
Expand All @@ -102,6 +115,7 @@ def test_checks():
color = FAIL

print "Network traffic collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)
print_data(info=info, message=message)

info = get_load_average()
if len(info) > 0:
Expand All @@ -112,7 +126,7 @@ def test_checks():
color = FAIL

print "Load collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)

print_data(info=info, message=message)

info = get_cpu_utilization()
if len(info) > 0:
Expand All @@ -123,6 +137,7 @@ def test_checks():
color = FAIL

print "CPU collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)
print_data(info=info, message=message)

info = processes_data_collector.collect()
if len(info) > 0:
Expand All @@ -133,11 +148,11 @@ def test_checks():
color = FAIL

print "Process collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)
print_data(info=info, message=message)



info = container_data_collector.collect()
print info
if len(info) > 0:
message = 'OK'
color = OKGREEN
Expand All @@ -146,6 +161,7 @@ def test_checks():
color = FAIL

print "Docker containers collector: {color}{message}{end}".format(color=color, message=message, end=ENDC)
print_data(info=info, message=message)


url = "{0}/api/test/{1}".format(settings.HOST, settings.SERVER_KEY)
Expand Down
71 changes: 25 additions & 46 deletions amonagent/modules/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,10 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.

import os
import stat
import array
import errno
import fcntl
import fnmatch
import glob
import platform
import re
import signal
import socket
import struct
import datetime
import getpass
import pwd
import ConfigParser
import StringIO

from string import maketrans

try:
import json
except ImportError:
import simplejson as json

# --------------------------------------------------------------
# timeout function to make sure some fact gathering
Expand Down Expand Up @@ -108,18 +89,13 @@ class Facts(object):
{ 'path' : '/usr/bin/pkg', 'name' : 'pkg' },
]

def __init__(self, load_on_init=True):
def __init__(self):

self.facts = {}

if load_on_init:
self.get_platform_facts()
self.get_distribution_facts()
self.get_platform_facts()
self.get_distribution_facts()


def populate(self):
return self.facts

# Platform
# platform.system() can be Linux, Darwin, Java, or Windows
def get_platform_facts(self):
Expand Down Expand Up @@ -371,25 +347,28 @@ def get_distribution_facts(self):


def get_distro():
distro = {}
f = Facts(load_on_init=False)
f.get_platform_facts()
f.get_distribution_facts()
distro = {}
try:
f = Facts()
except:
f = False


facts_filter = [
'distribution_version',
'distribution',
]
replaced_names = {
'distribution_version': 'version',
'distribution' : 'name'
}
for key, fact in f.facts.items():
if key in facts_filter:
reported_key = replaced_names[key]
distro[reported_key] = fact

if f:
facts_filter = [
'distribution_version',
'distribution',
]
replaced_names = {
'distribution_version': 'version',
'distribution' : 'name'
}
if type(f.facts) is dict:

return distro
for key, fact in f.facts.items():
if key in facts_filter:
reported_key = replaced_names[key]
distro[reported_key] = fact


print get_distro()
return distro
3 changes: 1 addition & 2 deletions amonagent/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
disk_check,
get_network_traffic,
get_ip_address,
get_cpu_info,
get_system_uuid
get_cpu_info
)
from amonagent.modules.containers import container_data_collector
from amonagent.modules.distro import get_distro
Expand Down
2 changes: 0 additions & 2 deletions packaging/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ amon_agent_deb: clean install_base
$(FPM_BUILD) -t deb \
-n amon-agent \
-d "python (>= 2.6)" \
-d "python-dev" \
-d "curl" \
-d "adduser" \
-d "sysstat" \
Expand All @@ -80,7 +79,6 @@ amon_agent_rpm: clean install_base
FPM_EDITOR="echo ''>>" \
$(FPM_BUILD) -t rpm \
-n "amon-agent" \
-d "python-devel" \
-d "curl" \
-d "sysstat" \
-d "git" \
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
author_email='martin@amon.cx',
zip_safe=False,
packages=find_packages(),
install_requires=['requests>=2.3.0', 'unidecode', 'docker-py==1.2.2', 'ansible<2.0'],
install_requires=['requests>=2.3.0', 'unidecode', 'docker-py==1.2.2'],
)

0 comments on commit 3ac527d

Please sign in to comment.