Memcached not working

I am trying to create a pipeline using the memcached plugin, however it is not working when I create a key in the cache in dictionary format.

Here's my pipeline:

input {
    udp {
        port => 514
        type => syslog
    }
}

filter {

    syslog_pri {}

    mutate {
        copy => {
            "[host][ip]" => "ip"
        }
    }

    memcached {
        hosts => ["localhost"]
        get => {
            "%{ip}" => "[host_detail]"
        }
    }

    ### Drop messages
    if "ksyncd_ksync_handle_asyncmsg" in [message] {drop {}}
    if "if_process_obj_index: Zero length TLV!" in [message] {drop {}}
    if "get tlv ppfeid" in [message] {drop {}}
    if "hw.chassis.startup_time update to" in [message] {drop {}}
    if "UI_LOGOUT_EVENT: User" in [message] {drop {}}
    if "UI_LOGIN_EVENT: User" in [message] {drop {}}
    if "UI_AUTH_EVENT: Authenticated user" in [message] {drop {}}
    if "UI_CHILD_EXITED: Child exited:" in [message] {drop {}}
    if "UI_CHILD_START: Starting child" in [message] {drop {}}
    if "UI_CHILD_STATUS: Cleanup child" in [message] {drop {}}
    if "Accepted password for" in [message] {drop {}}
    if "Accepted keyboard-interactive/pam" in [message] {drop {}}
    if "tac_send_authen: unexpected EOF from server" in [message] {drop {}}
    if "SSHD_LOGIN_FAILED: Login failed for user" in [message] {drop {}}
    if "error: PAM: authentication error for" in [message] {drop {}}
    if "Failed password for" in [message] {drop {}}
    if "Connection closed by" in [message] {drop {}}
    if "error: PAM: authentication information is unavailable for" in [message] {drop {}}
    if "exited, status 255" in [message] {drop {}}
    if "(root) CMD" in [message] {drop {}}
    if "bln3_script" in [message] {drop {}}
    if "backaggr" in [message] {drop {}}
    if "rpc command" in [message] {drop {}}
    if "hw.chassis.startup_time update to" in [message] {drop {}}
    if "SSHD_LOGIN_FAILED: Login failed for user" in [message] {drop {}}
    
}


output {
    stdout {
        codec => rubydebug        
    }
}

I'm loading the entries in the cache via a python script that reads a json file, I'm printing it right after the insertion and it's ok.

import json
from pprint import pprint
from typing import List
from pydantic import BaseModel
from pymemcache import Client, serde


class Host(BaseModel):
    ip: str
    hostname: str
    type: str
    vendor: str
    model: str


if __name__ == "__main__":

    with open("hosts.json") as hosts_file:
        data = json.load(hosts_file)
        
        hosts: List[Host] = []

        for i in data["hosts"]:
            hosts.append(Host(ip=i["ip"], hostname=i["hostname"], type=i["type"], vendor=i["vendor"], model=i["model"]))

        memcached: Client = Client("localhost", serde=serde.pickle_serde)
        memcached.flush_all()
        
        for host in hosts:
            memcached.set(host.ip, {"hostname": host.hostname, "type": host.type, "vendor": host.vendor, "model": host.model})

        for host in hosts:            
            print(memcached.get(host.ip))

Output pyhton file:

10.221.64.251
{'hostname': 'test1', 'type': 'router', 'vendor': 'Huawei', 'model': 'NE40X8'}
10.185.96.7
{'hostname': 'test2', 'type': 'router', 'vendor': 'Juniper', 'model': 'MX960'}
10.113.150.4
{'hostname': 'test3', 'type': 'router, 'vendor': 'Nokia', 'model': 'SR7750'}

My question is: does memcached plugin support dictionaries?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.