Skip to content

Commit

Permalink
Merge pull request #87 from ARGOeu/revert-85-maxcmdlength_increase
Browse files Browse the repository at this point in the history
Revert "ARGO-4445 Increase cmd querry size for publisher probe inspection"
  • Loading branch information
kzailac authored May 28, 2024
2 parents 22b7d5a + ab3ba9a commit 245f685
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 7 deletions.
4 changes: 0 additions & 4 deletions .gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Component relies on:
|-------------------|----------------------------------------------------|
| Configuration | `/etc/ams-publisher/ams-publisher.conf`|
| Daemon component | `/usr/bin/ams-publisherd` |
| Cache delivery | `ams-metric-to-queue` |
| Cache delivery | `/usr/bin/ams-alarm-to-queue, ams-metric-to-queue` |
| Init script (C6) | `/etc/init.d/ams-publisher` |
| SystemD Unit (C7) | `/usr/lib/systemd/system/ams-publisher.service` |
| Local caches | `/var/spool/ams-publisher/` |
Expand Down
2 changes: 2 additions & 0 deletions ams-publisher.spec
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Bridge from Nagios to the ARGO Messaging system

%files -n argo-nagios-ams-publisher
%defattr(-,root,root,-)
%{_bindir}/ams-alarm-to-queue
%{_bindir}/ams-metric-to-queue
%{_bindir}/ams-publisherd
%config(noreplace) %{_sysconfdir}/ams-publisher/ams-publisher-nagios.conf
Expand Down Expand Up @@ -104,6 +105,7 @@ Bridge from Sensu to the ARGO Messaging system

%files -n argo-sensu-ams-publisher
%defattr(-,root,root,-)
%{_bindir}/ams-alarm-to-queue
%{_bindir}/ams-metric-to-queue
%{_bindir}/ams-publisherd
%config(noreplace) %{_sysconfdir}/ams-publisher/ams-publisher-sensu.conf
Expand Down
5 changes: 5 additions & 0 deletions bin/ams-alarm-to-queue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/python3

from ams_publisher import alarmtoqueue

alarmtoqueue.main()
21 changes: 21 additions & 0 deletions config/ams-publisher-nagios.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,24 @@ AvroSchema = /etc/ams-publisher/metric_data.avsc
Retry = 5
Timeout = 60
SleepRetry = 300

[Queue_Alarms]
Directory = /var/spool/ams-publisher/alarms/
Rate = 10
Purge = True
PurgeEverySec = 300
MaxTemp = 300
MaxLock = 0
Granularity = 60

[Topic_Alarms]
Host = messaging-devel.argo.grnet.gr
Key = EGIKEY
Project = EGI
Bulksize = 100
Topic = alarms
MsgType = alarm
Avro = False
Retry = 5
Timeout = 60
SleepRetry = 300
21 changes: 21 additions & 0 deletions config/ams-publisher-sensu.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,24 @@ AvroSchema = /etc/ams-publisher/metric_data.avsc
Retry = 5
Timeout = 60
SleepRetry = 300

[Queue_Alarms]
Directory = /var/spool/ams-publisher/alarms/
Rate = 10
Purge = True
PurgeEverySec = 300
MaxTemp = 300
MaxLock = 0
Granularity = 60

[Topic_Alarms]
Host = messaging-devel.argo.grnet.gr
Key = EGIKEY
Project = EGI
Bulksize = 100
Topic = alarms
MsgType = alarm
Avro = False
Retry = 5
Timeout = 60
SleepRetry = 300
98 changes: 98 additions & 0 deletions pymod/alarmtoqueue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python

from messaging.message import Message
from messaging.error import MessageError
from messaging.queue.dqs import DQS

from ams_publisher import config
from ams_publisher import log

import argparse
import datetime
import os
import pwd
import pytz
import sys


CONF = '/etc/ams-publisher/ams-publisher.conf'


def seteuser(user):
os.setegid(user.pw_gid)
os.seteuid(user.pw_uid)


def build_msg(args, *headers):
msg = Message()
msg.header = dict()
msg.body = str()

timestamp, service, hostname, testname, status, nagioshost = headers

msg.header.update({'execution_time': timestamp})
msg.header.update({'service_flavour': service})
msg.header.update({'node_name': hostname})
msg.header.update({'test_name': testname})
msg.header.update({'status': status})

for bs in ['details', 'vo', 'site', 'roc', 'urlhistory', 'urlhelp']:
code = "msg.body += '%s: ' + args.%s + '\\n' if args.%s else ''" % (bs, bs, bs)
exec(code)

msg.text = True
return msg


def main():
parser = argparse.ArgumentParser()
lobj = log.Logger(sys.argv[0])
logger = lobj.get()
confopts = config.parse_config(logger)
nagioshost = confopts['general']['host']
tz = pytz.timezone(confopts['general']['timezone'])
timestamp = datetime.datetime.now(tz).strftime('%Y-%m-%dT%H:%M:%SZ')

parser.add_argument('--queue', required=True, nargs='+')

# msg headers
parser.add_argument('--service', required=True, type=str)
parser.add_argument('--hostname', required=True, type=str)
parser.add_argument('--testname', required=True, type=str)
parser.add_argument('--status', required=True, type=str)

# msg body
parser.add_argument('--details', required=False, type=str)
parser.add_argument('--vo', required=False, type=str)
parser.add_argument('--site', required=False, type=str)
parser.add_argument('--roc', required=False, type=str)
parser.add_argument('--urlhistory', required=False, type=str)
parser.add_argument('--urlhelp', required=False, type=str)

args = parser.parse_args()

seteuser(pwd.getpwnam(confopts['general']['runasuser']))

try:
for q in args.queue:
granularity = config.get_queue_granul(q)
mq = DQS(path=q, granularity=granularity)

msg = build_msg(args, timestamp, args.service, args.hostname, \
args.testname, args.status, nagioshost)
mq.add_message(msg)

except MessageError as e:
logger.error('Error constructing alarm - %s', repr(e))

except KeyError:
logger.error('No configured Queue for directory %s' % q)
queue_paths = list()
for (k, v) in confopts['queues'].items():
queue_paths.append('{0} - {1}'.format(k, v['directory']))
logger.error('Queues and directories found in config: %s' % ', '.join(queue_paths))
raise SystemExit(1)

except (OSError, IOError) as e:
logger.error(e)
raise SystemExit(1)
2 changes: 1 addition & 1 deletion pymod/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from multiprocessing import Process
from ams_publisher.shared import Shared

MAXCMDLENGTH = 1024
MAXCMDLENGTH = 128
STATSOCK = '/run/ams-publisher/sock'


Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ def get_ver():
'config/metric_data.avsc']),
('/usr/lib/systemd/system/', ['init/ams-publisher-nagios.service',
'init/ams-publisher-sensu.service'])],
scripts=['bin/ams-metric-to-queue', 'bin/ams-publisherd'])
scripts=['bin/ams-alarm-to-queue', 'bin/ams-metric-to-queue',
'bin/ams-publisherd'])

0 comments on commit 245f685

Please sign in to comment.