GRAPHIC: New Entity Operations™ Alpha Logo

EntityScript



core_alerts




# -*- coding: utf-8 -*-
"""
COPYRIGHT (C) 2020-2023 NEW ENTITY OPERATIONS INC. ALL RIGHTS RESERVED
INSTANCE: origin
MODIFIED: 2023/05/02
OVERVIEW:

core_alerts is a module to establish alert markers and related behavior.

There are some basic contextual examples included. They can be expanded
on even more and become more complex in various operator-defined ways too.

Usage: To setup a LOGGER, follow the convention below
# LOGGER
# Where to place: Place the LOGGER at the end of the method or function call
# you would like to log.

# Here is an example. This will only run if the routine finishes to the point
# where the LOGGER occurs: This calls core_alerts for the specific LOGGER
# function

get_DOCUMENTS_LOGGER = "[get_DOCUMENTS_LOGGER: "
get_DOCUMENTS_helper = "open file]"
print(get_DOCUMENTS_LOGGER+get_DOCUMENTS_helper+\
ALERT_LOGGING_WARNING(
 variable=get_DOCUMENTS_LOGGER+get_DOCUMENTS_helper
 )+"\n"
)

Alerts get scaled according to threat scores and put into appropriate buckets.

These scores can be built according to your specifications.

Anything that's logged with a score also has a specified logging type too.

These are user defined with some preset options available.

When to use this script: When a method or function call requires auditing later,
log it with this methodology.

Why to use: This could help audit internal process. Maybe it's ad views or
other operator defined methodologies that would be nice to confirm are taking
place.

Extra details: The 'START: ACTION',  and 'STOP: ACTION' areas are for 
 readability

They can break large files into sections of context that the programmer or
business team can easily inspect as a unit later on.

Areas of code that are easily tracked in operator-defined ways can help
understand 'system intent'.

Meaning, the 'START: ACTION' block goes at the beginning of the routine that
will be triggered upon whatever you're generating.
When the generated routine is fully spent, throw the 'STOP: ACTION' alert.

'STOP: ACTION' blocks can apply in tandem with other 'STOP: ACTION' blocks
but there can only be one 'START: BLOCK' containing a 'START: ACTION' for 
the first acting script and limited only by another 'START: BLOCK'.

To use an Action, put a similar convention into your code, but replace
anything contextual so it can be identified in the logs.

      EventLolli.update_ad_special__LOGGER = \
       "[Audited: EventLolli.update_ad_special: "
      EventLolli.update_ad_special__helper = \
      "check values] "
      EventLolli.update_ad_special__values = \
       "[UNIT: ms - "+STRING_INT_seconds_adjusted+"] "
      print(EventLolli.update_ad_special__LOGGER+\
       EventLolli.update_ad_special__helper+\
        ACTION_AUDITED(variable=EventLolli.update_ad_special__LOGGER+\
         EventLolli.update_ad_special__helper+\
          EventLolli.update_ad_special__values)+\
           "\n")
      print(
       "---------- STOP: ACTION -" \
       " [Audited: EventLolli.update_ad_special: check values] ----------"
      )
      #*******************************************************************#
      # STOP: ACTION -                                                    #
      # [Audited: EventLolli.update_ad_special: check values] ----------" #
      #*******************************************************************#

Allowed Hash Imports: Standard ways to provide on the fly time-based
 hashes. The basic install provides a sha1 to get entropy and speed,
 but sha1 isn't compliant in certain situations. You can upgrade according
 to your needs at any time

"""
__version__ = "0.0.8"
__author__ = "Ryan McKenna"
__copyright__ = "Copyright (C) 2020-2023 New Entity Operations Inc."
__credits__ = [
 "Ryan McKenna",
 "New Entity Operations Inc.", "New Entity Operations, LLC"]
__email__ = "Operator@NewEntityOperations.com"
__license__ = "New Entity License"
__maintainer__ = "Ryan McKenna"
__status__ = "Production"

## MODE-> facilities
from MODE.facilities import (AUDIT_TAG, Cure, EVENT_TAG,
 ENTITYSCRIPT_RECORDER_TAG, KING_SLUG_RECORDER_TAG, PATH_INSTANCE,
 SEARCH_RECORDER_TAG, sha1, THREAT_SCORE_FAILURE, THREAT_SCORE_INFO,
 THREAT_SCORE_WARNING, QUEEN_SLUG_RECORDER_TAG)

## Imports: Custom
from core_middlelayer import (DASH_UTIL, DATASHEETFOLDER, DIRLOG,
 ENTITYSLUG, EXTDS, EXTENTITY, LOG)

## Imports: Log makers
from core_interface import (
 TimeStamp as TS,
)

def LogMaker_date():
 return(TS.time_stamp_time())

def LogMaker_time():
 return(TS.date_stamp_day())

def ALERT_LOGGING_INFO(variable="[DEFAULT]"):
    """
    ALERT with the 'LOGGING_INFO' option

    """
    ALERT_INFO_STANDARD = """[EVENTTIME: """+\
     LogMaker_time()+"""] ["""+\
     LogMaker_date()+"""] ["""+\
     THREAT_SCORE_INFO+"""] [ALERT: INFO SLUG] """+\
     variable+"\n"
    with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as logger_INFO:
     logger_INFO.write(ALERT_INFO_STANDARD)
    logger_INFO.close()
    return(ALERT_INFO_STANDARD)

def ALERT_LOGGING_FAILURE(variable=" [DEFAULT] "):
    """
    ALERT with the 'LOGGING_FAILURE' option

    """
    ALERT_FAILURE_STANDARD = """[EVENTTIME: """+\
     LogMaker_time()+"""] ["""+\
     LogMaker_date()+"""] ["""+\
     THREAT_SCORE_FAILURE+"""] [ALERT: FAILURE SLUG] """+\
     variable+"\n"
    with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as logger_FAILURE:
     logger_FAILURE.write(ALERT_FAILURE_STANDARD)
    logger_FAILURE.close()
    return(ALERT_FAILURE_STANDARD)

def ALERT_LOGGING_WARNING(variable="[DEFAULT] "):
    """
    ALERT with the 'LOGGING_WARNING' option

    """
    ALERT_WARNING_STANDARD = """[EVENTTIME: """+\
     LogMaker_time()+"""] ["""+\
     LogMaker_date()+"""] ["""+\
     THREAT_SCORE_WARNING+"""] [ALERT: WARNING SLUG] """+\
     variable+"\n"
    with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as logger_WARNING:
     logger_WARNING.write(ALERT_WARNING_STANDARD)
    logger_WARNING.close()
    return(ALERT_WARNING_STANDARD)

## ACTION: Custom action logging
def ACTION_REGULAR(variable=" [DEFAULT] "):
    """
    ACTION with the 'REGULAR'

    """
    ACTION_REGULAR_STANDARD = """[EVENTTIME: """+\
     LogMaker_time()+"""] ["""+\
     LogMaker_date()+"""] ["""+\
     EVENT_TAG+"""] [ACTION: REGULAR SLUG] """+\
     variable+"\n"
    with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as action_REGULAR:
     action_REGULAR.write(ACTION_REGULAR_STANDARD)
    action_REGULAR.close()
    return(ACTION_REGULAR_STANDARD)

## ACTION_AUDITED is the standard AUDIT block used
def ACTION_AUDITED(variable=" [DEFAULT] "):
    """
    ACTION with 'AUDITED'

    """
    ACTION_AUDITED_STANDARD = """[EVENTTIME: """+\
     LogMaker_time()+"""] ["""+\
     LogMaker_date()+"""] ["""+\
     AUDIT_TAG+"""] [ACTION: AUDITED SLUG]"""+\
     variable+"\n"
    with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as action_AUDITED:
     action_AUDITED.write(ACTION_AUDITED_STANDARD)
    action_AUDITED.close()
    return(ACTION_AUDITED_STANDARD)

## All of the'ACTION_X...' methods take various action types
# These action types are generated from the key-directory above
def ACTION_ENTITYSCRIPT_RECORDER(variable=" [DEFAULT] "):
    """
    ACTION with 'SEARCH_RECORDER'

    """
    ACTION_SEARCH_RECORDER_STANDARD = """[EVENTTIME: """+\
     LogMaker_time()+"""] ["""+\
     LogMaker_date()+"""] ["""+\
     ENTITYSCRIPT_RECORDER_TAG+"""] [ACTION: SEARCH_RECORDED]"""+\
     variable+"\n"
    with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as action_SEARCH_RECORDER:
     action_SEARCH_RECORDER.write(ACTION_SEARCH_RECORDER_STANDARD)
    action_SEARCH_RECORDER.close()
    return(ACTION_SEARCH_RECORDER_STANDARD)

def ACTION_KING_SLUG_RECORDER(variable=" [DEFAULT] "):
    """
    ACTION with 'KING_SLUG_RECORDER'

    """
    ACTION_KING_SLUG_RECORDER_STANDARD = """[EVENTTIME: """+\
     LogMaker_time()+"""] ["""+\
     LogMaker_date()+"""] ["""+\
     KING_SLUG_RECORDER_TAG+"""] [ACTION: KING_SLUG_RECORDED]"""+\
     variable+"\n"
    with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as action_KING_SLUG_RECORDER:
     action_KING_SLUG_RECORDER.write(ACTION_KING_SLUG_RECORDER_STANDARD)
    action_KING_SLUG_RECORDER.close()
    return(ACTION_KING_SLUG_RECORDER_STANDARD)

def ACTION_QUEEN_SLUG_RECORDER(variable=" [DEFAULT] "):
    """
    ACTION with 'QUEEN_SLUG_RECORDER'

    """
    ACTION_QUEEN_SLUG_RECORDER_STANDARD = """[EVENTTIME: """+\
     LogMaker_time()+"""] ["""+\
     LogMaker_date()+"""] ["""+\
     QUEEN_SLUG_RECORDER_TAG+"""] [ACTION: QUEEN_SLUG_RECORDED]"""+\
     variable+"\n"
    with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as action_QUEEN_SLUG_RECORDER:
     action_QUEEN_SLUG_RECORDER.write(ACTION_QUEEN_SLUG_RECORDER_STANDARD)
    action_QUEEN_SLUG_RECORDER.close()
    return(ACTION_QUEEN_SLUG_RECORDER_STANDARD)

def ACTION_SEARCH_RECORDER(variable=" [DEFAULT] "):
    """
    ACTION with 'SEARCH_RECORDER'

    """
    ACTION_SEARCH_RECORDER_STANDARD = """[EVENTTIME: """+\
     LogMaker_time()+"""] ["""+\
     LogMaker_date()+"""] ["""+\
     SEARCH_RECORDER_TAG+"""] [ACTION: SEARCH_RECORDED]"""+\
     variable+"\n"
    with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as action_SEARCH_RECORDER:
     action_SEARCH_RECORDER.write(ACTION_SEARCH_RECORDER_STANDARD)
    action_SEARCH_RECORDER.close()
    return(ACTION_SEARCH_RECORDER_STANDARD)

## Loader: Prototype function testers
class LOADER_DS:
 """
 LOADER to check various .ds file attributes
 """
 def load_specific(variable="[DEFAULT] "):
  """
  Run standard parse/load tests on 1 .ds file
  """
  PARSE_DS = """[EVENTTIME: """+\
   LogMaker_time()+"""] ["""+\
   LogMaker_date()+"""] ["""+\
   EVENT_TAG+"""] [LOADER_DS: DS SLUG]"""+\
   variable+"\n"
  with open(PATH_INSTANCE+DIRLOG+LOG, 'a') as LOADER_DS:
   LOADER_DS.write(PARSE_DS)
  LOADER_DS.close()
  return(PARSE_DS)

 def load_all():
  """
  Run standard full tests on all .ds files: Default none specified
  """
  pass

def LOADER_ENTITY():
 """
 LOADER to check various .entity file attributes: Default none specified
 """
 def load_specific():
  """
  Run standard full tests on 1 .entity file: Default none specified
  """
  pass

 def load_all():
  """
  Run standard full tests on all .entity files: Default none specified
  """
  pass

def LOADER_ALL_FUNCTIONS():
 """
 See if each function can load and run: Default none specified
 """
 pass



Return HOME