window.median

נתמך ב:
window.median(numeric_values, should_ignore_zero_values)

תיאור

הפונקציה מחזירה את החציון של ערכי הקלט. אם יש 2 ערכי חציון, רק אחד מהם ייבחר באופן לא דטרמיניסטי כערך ההחזרה.

סוגי נתונים של פרמטרים

INT|FLOAT, BOOL

סוג הערך שמוחזר

FLOAT

דוגמאות קוד

דוגמה 1

בדוגמה הזו, הפונקציה מחזירה את ערך החציון אם ערכי הקלט לא אפס.

rule median_file_size {
    meta:
    events:
      $e.metadata.event_type = "FILE_COPY"
        $userid = $e.principal.user.userid
    match:
      $userid over 1h
    outcome:
      $median_file_size = window.median($e.principal.file.size) // returns 2 if the file sizes in the match window are [1, 2, 3]
  condition:
      $e
}
דוגמה 2

בדוגמה הזו מוחזרת החציון כשנתוני הקלט כוללים כמה ערכים אפסיים שלא צריך להתעלם מהם.

rule median_file_size {
    meta:
    events:
      $e.metadata.event_type = "FILE_COPY"
        $userid = $e.principal.user.userid
    match:
      $userid over 1h
    outcome:
      $median_file_size = window.median($e.principal.file.size) // returns 1 if the file sizes in the match window are [0,0, 1, 2, 3]
  condition:
      $e
}
דוגמה 3

בדוגמה הזו, הפונקציה מחזירה את ערך החציון כשהקלט כולל כמה ערכים של אפס שצריך להתעלם מהם.

rule median_file_size {
    meta:
    events:
      $e.metadata.event_type = "FILE_COPY"
        $userid = $e.principal.user.userid
    match:
      $userid over 1h
    outcome:
      $median_file_size = window.median($e.principal.file.size, true) // returns 2 if the file sizes in the match window are [0,0, 1, 2, 3]
  condition:
      $e
}
דוגמה 4

בדוגמה הזו מוחזר החציון כשהקלט כולל את כל ערכי האפס שצריך להתעלם מהם.

rule median_file_size {
    meta:
    events:
      $e.metadata.event_type = "FILE_COPY"
        $userid = $e.principal.user.userid
    match:
      $userid over 1h
    outcome:
      $median_file_size = window.median($e.principal.file.size) // returns 0 if the file sizes in the match window are [0,0]
  condition:
      $e
}
דוגמה 5

בדוגמה הזו אפשר לראות שאם יש כמה ערכי חציון, רק אחד מהם מוחזר.

rule median_file_size {
    meta:
    events:
      $e.metadata.event_type = "FILE_COPY"
        $userid = $e.principal.user.userid
    match:
      $userid over 1h
    outcome:
      $median_file_size = window.median($e.principal.file.size) // returns 1 if the file sizes in the match window are [1, 2, 3, 4]
  condition:
      $e
}