Livestatus TCP No Reply

Hello Everyone!,

I know this issue have been published here before, I’ve read all the threads and tried all the possible solutions, but it did not resolve my issue!

I have been trying to receive some data for a specific service from Check_MK via livestatus TCP,I have enabled the configuration as stated in the documentation here: Retrieving and processing status data via an API

the python example provided seems to be outdated because when I tried it an SSL Error appeared , and I had to alter the script a little bit to make it support ssl via wrapping the TCP socket. anyway here the script i’m using:


import json, os, socket
import ssl

address = ('10.161.155.154', 6557)

# # connect to Livestatus
family = socket.AF_INET if type(address) == tuple else socket.AF_UNIX
sock = socket.socket(family, socket.SOCK_STREAM)

# WRAP SOCKET
wrappedSocket = ssl.wrap_socket(sock)

# send our request and let Livestatus know we're done
wrappedSocket.connect(address)
cmd = "GET services\nFilter: description = SCCPFWSTATS\nFilter: host_name ~ SMSFW\nFilter: host_state = 0\nStats: sum perf_data\nOutputFormat: csv\n"
print(cmd)
wrappedSocket.sendall(cmd)
wrappedSocket.shutdown(socket.SHUT_WR)


# receive the reply as a CSV string
chunks = []
while len(chunks) == 0 or chunks[-1] != "":
    chunks.append(wrappedSocket.recv(4096))
wrappedSocket.close()
reply = "".join(chunks)

print(reply)

when i run the script i receive an empty message:

[root@smsfw01 plugins]# ./sccptotal.py 
GET services
Filter: description = SCCPFWSTATS\n
Filter: host_name ~ SMSFW\n
Filter: host_state = 0\n
Stats: sum perf_data
OutputFormat: csv



when i tail the logs of stunnel i can see that there is connection and a reply:

==> stunnel-server.log.1 <==
2021.03.29 07:51:54 LOG5[6754]: Service [live-tls] accepted connection from unnamed socket
2021.03.29 07:51:54 LOG5[6754]: Service [live-tls] connected remote server from unnamed socket
2021.03.29 07:51:54 LOG5[6754]: Connection closed: 0 byte(s) sent to TLS, 135 byte(s) sent to socket

note: there is no cmc.log error.

when i use livestatus from the check_mk server, by binding to the socket directly without TCP i receive an answer:

OMD[glo]:~$ ./test.py 
GET services
Filter: description = SCCPFWSTATS
Filter: host_name ~ SMSFW
Filter: host_state = 0
Stats: sum perf_data
OutputFormat: csv

MOFSMrequest=0.000000 MOFSMresponse=0.000000 MP_Rej_Err=0.000000 MP_Ret_Err=80.000000 MTFSMSuccessRate=192.260906 MTFSMrequest=433.000000 MTFSMresponse=415.000000 SRISMSuccessRate=189.933025 SRISMrequest=899.000000 SRISMresponse=854.000000 TC_ABORT=1.000000 TC_BEGIN=1235.000000 TC_CONT=364.000000 TC_END=1251.000000 TC_PARSEERR=1.000000 TC_UNIDF=0.000000 TotalBlocked=1.000000 TotalMSU=2852.000000 TotalPassed=2851.000000 averagePDUProcessingTime=1.481000 maximumPDUProcessingTime=8.000000 minimumPDUProcessingTime=1.000000 statsPeriodMillis=120000.000000

or even using lq to receive i get a reply:

OMD[glo]:~$ lq "GET services\nFilter: description = SCCPFWSTATS\nFilter: host_name ~ SMSFW\nFilter: host_state = 0\nStats: sum perf_data\nOutputFormat: csv\n"
MOFSMrequest=0.000000 MOFSMresponse=0.000000 MP_Rej_Err=0.000000 MP_Ret_Err=91.000000 MTFSMSuccessRate=173.413708 MTFSMrequest=409.000000 MTFSMresponse=355.000000 SRISMSuccessRate=191.319255 SRISMrequest=918.000000 SRISMresponse=878.000000 TC_ABORT=1.000000 TC_BEGIN=1257.000000 TC_CONT=337.000000 TC_END=1251.000000 TC_PARSEERR=0.000000 TC_UNIDF=0.000000 TotalBlocked=3.000000 TotalMSU=2846.000000 TotalPassed=2843.000000 averagePDUProcessingTime=1.383000 maximumPDUProcessingTime=8.000000 minimumPDUProcessingTime=0.000000 statsPeriodMillis=120000.000000

Thanks for taking the time and reading my post any help would be appreciated!

Hello!
i fixed the issue by referring to this thread Encrypted Livestatus with Python - Bug?, commented out wrappedSocket.shutdown(socket.SHUT_WR) and everything worked fine!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact @fayepal if you think this should be re-opened.