Changeset 494:edbf2d4d41db
- Timestamp:
- 10/14/08 13:59:19
(3 months ago)
- Author:
- Brian Warner <warner@allmydata.com>
- branch:
- default
- Message:
incident classifiers: change the function signature, now it just takes a trigger dict
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r493 |
r494 |
|
| 1 | 1 | 2008-10-14 Brian Warner <warner@allmydata.com> |
|---|
| | 2 | |
|---|
| | 3 | * foolscap/logging/gatherer.py |
|---|
| | 4 | (IncidentGathererService.classify_incident): change the classifier |
|---|
| | 5 | function signature: now it just takes a single 'trigger' dict. |
|---|
| | 6 | * foolscap/test/test_logging.py: update to match |
|---|
| | 7 | * doc/logging.xhtml (gatherer): same |
|---|
| 2 | 8 | |
|---|
| 3 | 9 | * foolscap/logging/gatherer.py |
|---|
| … | … | |
| 6 | 12 | them as plugins with classification functions. |
|---|
| 7 | 13 | (INCIDENT_GATHERER_TACFILE): update example text to match |
|---|
| | 14 | |
|---|
| 8 | 15 | * foolscap/test/test_logging.py (IncidentGatherer): test it |
|---|
| 9 | 16 | (Gatherer.test_wrongdir): exercise another error case |
|---|
| r493 |
r494 |
|
| 898 | 898 | starts.</p> |
|---|
| 899 | 899 | |
|---|
| 900 | | <p>The <code>classify_incident()</code> function will accept a triggering |
|---|
| 901 | | event and a pathname (from which preceding log events can be extracted, if |
|---|
| 902 | | desired), and should return a list of categories. Each incident can wind up |
|---|
| 903 | | in multiple categories. If no function finds a category for the incident, it |
|---|
| 904 | | will be added to the "unknown" category. All incidents are added to the "all" |
|---|
| 905 | | category.</p> |
|---|
| | 900 | <p>The <code>classify_incident()</code> function will accept a single |
|---|
| | 901 | triggering event (a regular log Event dictionary, see logfiles.xhtml for |
|---|
| | 902 | details, which can be examined as follows:</p> |
|---|
| | 903 | |
|---|
| | 904 | <pre class="python"> |
|---|
| | 905 | def classify_incident(trigger): |
|---|
| | 906 | m = trigger.get('message', '') |
|---|
| | 907 | if "Tub.connectorFinished:" in m: |
|---|
| | 908 | return 'foolscap-tubconnector' |
|---|
| | 909 | </pre> |
|---|
| | 910 | |
|---|
| | 911 | <p>The function should return a list (or set) of categories, or a single |
|---|
| | 912 | category string, or None. Each incident can wind up in multiple categories. |
|---|
| | 913 | If no function finds a category for the incident, it will be added to the |
|---|
| | 914 | "unknown" category. All incidents are added to the "all" category.</p> |
|---|
| 906 | 915 | |
|---|
| 907 | 916 | <p>The <code>classified/</code> directory will contain a file for each |
|---|
| r493 |
r494 |
|
| 511 | 511 | categories = set() |
|---|
| 512 | 512 | for f in self.classifiers: |
|---|
| 513 | | c = f(tubid_s, incident) |
|---|
| | 513 | (header, events) = incident |
|---|
| | 514 | trigger = header["trigger"] |
|---|
| | 515 | c = f(trigger) |
|---|
| 514 | 516 | if c: # allow the classifier to return None, or [], or ["foo"] |
|---|
| 515 | 517 | if isinstance(c, str): |
|---|
| … | … | |
| 553 | 555 | # import re |
|---|
| 554 | 556 | # TUBCON_RE = re.compile(r'^Tub.connectorFinished: WEIRD, <foolscap.negotiate.TubConnector instance at \w+> is not in \[') |
|---|
| 555 | | # def classify_incident(nodeid_s, incident): |
|---|
| | 557 | # def classify_incident(trigger): |
|---|
| 556 | 558 | # # match some foolscap messages |
|---|
| 557 | | # (header, events) = incident |
|---|
| 558 | | # trigger = header['trigger'] |
|---|
| 559 | 559 | # m = trigger.get('message', '') |
|---|
| 560 | 560 | # if TUBCON_RE.search(m): |
|---|
| r493 |
r494 |
|
| 1012 | 1012 | d.addCallback(lambda res: ig.disownServiceParent()) |
|---|
| 1013 | 1013 | |
|---|
| 1014 | | def classify_boom(nodeid_s, (header,events)): |
|---|
| 1015 | | if "boom" in header["trigger"].get("message",""): |
|---|
| | 1014 | def classify_boom(trigger): |
|---|
| | 1015 | if "boom" in trigger.get("message",""): |
|---|
| 1016 | 1016 | return "boom" |
|---|
| 1017 | | def classify_foom(nodeid_s, (header,events)): |
|---|
| 1018 | | if "foom" in header["trigger"].get("message",""): |
|---|
| | 1017 | def classify_foom(trigger): |
|---|
| | 1018 | if "foom" in trigger.get("message",""): |
|---|
| 1019 | 1019 | return "foom" |
|---|
| 1020 | 1020 | |
|---|
| … | … | |
| 1029 | 1029 | f = open(foomfile, "w") |
|---|
| 1030 | 1030 | f.write(''' |
|---|
| 1031 | | def classify_incident(nodeid_s, (header,events)): |
|---|
| 1032 | | if "foom" in header["trigger"].get("message",""): |
|---|
| | 1031 | def classify_incident(trigger): |
|---|
| | 1032 | if "foom" in trigger.get("message",""): |
|---|
| 1033 | 1033 | return "foom" |
|---|
| 1034 | 1034 | ''') |
|---|