mirror of
https://github.com/gnustep/libs-ec.git
synced 2025-02-22 11:21:28 +00:00
add alarm tool
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36946 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9a0322ed74
commit
f3770306f3
4 changed files with 243 additions and 3 deletions
213
AlarmTool.m
Normal file
213
AlarmTool.m
Normal file
|
@ -0,0 +1,213 @@
|
||||||
|
|
||||||
|
/** Enterprise Control Configuration and Logging
|
||||||
|
|
||||||
|
Copyright (C) 2012 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
Date: Febrary 2010
|
||||||
|
Originally developed from 1996 to 2012 by Brainstorm, and donated to
|
||||||
|
the FSF.
|
||||||
|
|
||||||
|
This file is part of the GNUstep project.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02111 USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#import "EcAlarm.h"
|
||||||
|
#import "EcProcess.h"
|
||||||
|
#import "EcUserDefaults.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
NSUserDefaults *defs;
|
||||||
|
EcAlarm *alrm;
|
||||||
|
NSArray *args;
|
||||||
|
NSString *cnam;
|
||||||
|
NSString *host;
|
||||||
|
NSString *comp;
|
||||||
|
NSString *mobj;
|
||||||
|
NSString *pref;
|
||||||
|
NSString *prob;
|
||||||
|
NSString *proc;
|
||||||
|
NSString *repr;
|
||||||
|
NSString *text;
|
||||||
|
NSString *str;
|
||||||
|
id proxy;
|
||||||
|
EcAlarmEventType type;
|
||||||
|
EcAlarmProbableCause cause;
|
||||||
|
EcAlarmSeverity severity;
|
||||||
|
CREATE_AUTORELEASE_POOL(arp);
|
||||||
|
|
||||||
|
pref = EC_DEFAULTS_PREFIX;
|
||||||
|
if (nil == pref)
|
||||||
|
{
|
||||||
|
pref = @"";
|
||||||
|
}
|
||||||
|
defs = [NSUserDefaults userDefaultsWithPrefix: pref
|
||||||
|
strict: EC_DEFAULTS_STRICT];
|
||||||
|
|
||||||
|
args = [[NSProcessInfo processInfo] arguments];
|
||||||
|
if ([args containsObject: @"--help"] == YES)
|
||||||
|
{
|
||||||
|
printf("AlarmTool ... options are\n");
|
||||||
|
printf("-Cause NN (no default)\n");
|
||||||
|
printf("\tSpecify probable cause of alarm (and implicitly the even type)\n");
|
||||||
|
printf("-Component NN (empty)\n");
|
||||||
|
printf("\tSpecify the name of the component raising the alarm.\n");
|
||||||
|
printf("-Problem NN (no default)\n");
|
||||||
|
printf("\tSpecify the specific problem causing the alarm. May be omitted for a clear.\n");
|
||||||
|
printf("-Process NN (no default)\n");
|
||||||
|
printf("\tSpecify the name of the process raising the alarm.\n");
|
||||||
|
printf("-Repair NN (no default)\n");
|
||||||
|
printf("\tSpecify the proposed repair action. May be omitted for a clear.\n");
|
||||||
|
printf("-Severity NN (clear)\n");
|
||||||
|
printf("\tSpecify the severity (clear, warning, minor, major, or critical)\n");
|
||||||
|
printf("-Text NN (none)\n");
|
||||||
|
printf("\tSpecify the additional text to be logged\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
str = [defs stringForKey: @"Cause"];
|
||||||
|
if (nil == str)
|
||||||
|
{
|
||||||
|
NSLog(@"Missing Cause, try --help", str);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
cause = EcAlarmVersionMismatch;
|
||||||
|
while (cause > EcAlarmProbableCauseUnknown)
|
||||||
|
{
|
||||||
|
NSString *s = [EcAlarm stringFromProbableCause: cause];
|
||||||
|
|
||||||
|
if (nil != s && [s caseInsensitiveCompare: str] == NSOrderedSame)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cause--;
|
||||||
|
}
|
||||||
|
if (EcAlarmProbableCauseUnknown == cause)
|
||||||
|
{
|
||||||
|
NSMutableArray *ma = [NSMutableArray arrayWithCapacity: 100];
|
||||||
|
|
||||||
|
cause = EcAlarmVersionMismatch;
|
||||||
|
while (cause > EcAlarmProbableCauseUnknown)
|
||||||
|
{
|
||||||
|
NSString *s = [EcAlarm stringFromProbableCause: cause];
|
||||||
|
|
||||||
|
if (nil != s)
|
||||||
|
{
|
||||||
|
[ma addObject: s];
|
||||||
|
}
|
||||||
|
cause--;
|
||||||
|
}
|
||||||
|
[ma sortUsingSelector: @selector(compare:)];
|
||||||
|
NSLog(@"Probable Cause (%@) unknown, try one of %@", str, ma);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
type = [EcAlarm eventTypeFromProbableCause: cause];
|
||||||
|
|
||||||
|
str = [defs stringForKey: @"Severity"];
|
||||||
|
if (nil == str)
|
||||||
|
severity = EcAlarmSeverityCleared;
|
||||||
|
else if ([str caseInsensitiveCompare: @"clear"] == NSOrderedSame)
|
||||||
|
severity = EcAlarmSeverityCleared;
|
||||||
|
else if ([str caseInsensitiveCompare: @"warning"] == NSOrderedSame)
|
||||||
|
severity = EcAlarmSeverityWarning;
|
||||||
|
else if ([str caseInsensitiveCompare: @"minor"] == NSOrderedSame)
|
||||||
|
severity = EcAlarmSeverityMinor;
|
||||||
|
else if ([str caseInsensitiveCompare: @"major"] == NSOrderedSame)
|
||||||
|
severity = EcAlarmSeverityMajor;
|
||||||
|
else if ([str caseInsensitiveCompare: @"critical"] == NSOrderedSame)
|
||||||
|
severity = EcAlarmSeverityCritical;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"Severity (%@) unknown, try --help", str);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
comp = [defs stringForKey: @"Component"];
|
||||||
|
proc = [defs stringForKey: @"Process"];
|
||||||
|
if ([proc length] == 0)
|
||||||
|
{
|
||||||
|
NSLog(@"No Process specified, try --help");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
mobj = EcMakeManagedObject(nil, proc, comp);
|
||||||
|
|
||||||
|
prob = [defs stringForKey: @"Problem"];
|
||||||
|
if ([prob length] == 0)
|
||||||
|
{
|
||||||
|
NSLog(@"No Problem specified, try --help");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
repr = [defs stringForKey: @"Repair"];
|
||||||
|
if (severity != EcAlarmSeverityCleared && [repr length] == 0)
|
||||||
|
{
|
||||||
|
NSLog(@"No Repair specified, try --help");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
text = [defs stringForKey: @"Text"];
|
||||||
|
|
||||||
|
alrm = [EcAlarm alarmForManagedObject: mobj
|
||||||
|
at: nil
|
||||||
|
withEventType: type
|
||||||
|
probableCause: cause
|
||||||
|
specificProblem: prob
|
||||||
|
perceivedSeverity: severity
|
||||||
|
proposedRepairAction: repr
|
||||||
|
additionalText: text];
|
||||||
|
|
||||||
|
cnam = [defs stringForKey: @"CommandName"];
|
||||||
|
if (cnam == nil)
|
||||||
|
{
|
||||||
|
cnam = @"Command";
|
||||||
|
}
|
||||||
|
|
||||||
|
host = [defs stringForKey: @"CommandHost"];
|
||||||
|
if ([host length] == 0)
|
||||||
|
{
|
||||||
|
host = [[NSHost currentHost] name];
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy = [NSConnection rootProxyForConnectionWithRegisteredName: cnam
|
||||||
|
host: host
|
||||||
|
usingNameServer: [NSSocketPortNameServer sharedInstance]];
|
||||||
|
|
||||||
|
if (nil == proxy)
|
||||||
|
{
|
||||||
|
NSLog(@"Unable to contact %@ on %@", cnam, host);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_DURING
|
||||||
|
{
|
||||||
|
[(id<Command>)proxy alarm: alrm];
|
||||||
|
}
|
||||||
|
NS_HANDLER
|
||||||
|
{
|
||||||
|
NSLog (@"Could not send alarm to server: %@", localException);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
NS_ENDHANDLER
|
||||||
|
|
||||||
|
RELEASE(arp);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,9 +1,10 @@
|
||||||
2013-08-05 Richard Frith-Macdonald <rfm@gnu.org>
|
2013-08-05 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* AlarmTool.m: Tool to raise/clear alarms
|
||||||
* LogTool.m: Tool to generate logs
|
* LogTool.m: Tool to generate logs
|
||||||
* Terminate.m: Cleanups
|
* Terminate.m: Cleanups
|
||||||
* GNUmakefile: Build new tool
|
* GNUmakefile: Build new tools
|
||||||
* ECCL.h: Document new tool
|
* ECCL.h: Document new tools
|
||||||
|
|
||||||
2013-07-12 Richard Frith-Macdonald <rfm@gnu.org>
|
2013-07-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
22
ECCL.h
22
ECCL.h
|
@ -39,6 +39,25 @@
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<heading>The AlarmTool command line tool</heading>
|
||||||
|
<p>The AlarmTool command line tool provides a mechanism to raise and
|
||||||
|
clear alarms (using the ECCL alarm system) from a process which is
|
||||||
|
not itsself ECCL enabled (ie not built using the ECCL classes).<br />
|
||||||
|
You may use this to generate logging from shell scripts
|
||||||
|
or from Java servlets etc.
|
||||||
|
</p>
|
||||||
|
<p>The tool requires at least four (usually six) arguments:<br />
|
||||||
|
'-Cause NN' the probable cause of the alarm (type of problem).<br />
|
||||||
|
'-Component NN' the component which raised the alarm.<br />
|
||||||
|
'-Problem NN' the specific problem which raised the alarm.<br />
|
||||||
|
'-Process NN' the name of the process which raised the alarm.<br />
|
||||||
|
'-Repair NN' a proposed repair action to fix the issue.<br />
|
||||||
|
'-Severity NN' the severity of the problem (defaults to 'cleared',
|
||||||
|
in which case the Repair action is not required).<br />
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<heading>The LogTool command line tool</heading>
|
<heading>The LogTool command line tool</heading>
|
||||||
<p>The LogTool command line tool provides a mechanism to log various
|
<p>The LogTool command line tool provides a mechanism to log various
|
||||||
|
@ -56,13 +75,14 @@
|
||||||
to generating a 'Warn' log.
|
to generating a 'Warn' log.
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<heading>The Terminate command line tool</heading>
|
<heading>The Terminate command line tool</heading>
|
||||||
<p>The Terminate command line tool provides a mechanism to shut down
|
<p>The Terminate command line tool provides a mechanism to shut down
|
||||||
an ECCL host. This tool contacts a Command server and tells it to
|
an ECCL host. This tool contacts a Command server and tells it to
|
||||||
shut down all it's local client process and the shut itsself down.
|
shut down all it's local client process and the shut itsself down.
|
||||||
</p>
|
</p>
|
||||||
<p>You may use -CommandHost and -CommandName to specify a Command
|
<p>You may use '-CommandHost' and '-CommandName' to specify a Command
|
||||||
server to contact, otherwise the default local Command server is
|
server to contact, otherwise the default local Command server is
|
||||||
contacted (or if there is no local server, any available Command
|
contacted (or if there is no local server, any available Command
|
||||||
server on the local network is contacted).
|
server on the local network is contacted).
|
||||||
|
|
|
@ -64,6 +64,7 @@ TOOL_NAME = \
|
||||||
Command \
|
Command \
|
||||||
Console \
|
Console \
|
||||||
Control \
|
Control \
|
||||||
|
AlarmTool \
|
||||||
LogTool \
|
LogTool \
|
||||||
Terminate \
|
Terminate \
|
||||||
|
|
||||||
|
@ -80,6 +81,11 @@ Control_OBJC_FILES = Control.m EcControl.m EcClientI.m NSFileHandle+Printf.m
|
||||||
Control_TOOL_LIBS += -lECCL
|
Control_TOOL_LIBS += -lECCL
|
||||||
Control_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
|
Control_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
|
||||||
|
|
||||||
|
AlarmTool_OBJC_FILES = AlarmTool.m
|
||||||
|
AlarmTool_TOOL_LIBS += -lECCL
|
||||||
|
AlarmTool_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
|
||||||
|
AlarmTool_CPPFLAGS += ${ECCL_CPPFLAGS}
|
||||||
|
|
||||||
LogTool_OBJC_FILES = LogTool.m
|
LogTool_OBJC_FILES = LogTool.m
|
||||||
LogTool_TOOL_LIBS += -lECCL
|
LogTool_TOOL_LIBS += -lECCL
|
||||||
LogTool_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
|
LogTool_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
|
||||||
|
|
Loading…
Reference in a new issue