Tclsh snmp format - tcl

I am trying to get a value from an instance with OID using tcl command.
In TCL, the command works:
% set snmp_result [snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]
iso.3.6.1.4.1.31926.2.1.1.19.1 = INTEGER: -57
I am trying to get the number -57 only, so I wrote a tclsh script:
set snmp_result [snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]
set splitted_result [split $snmp_result ""]
puts [lindex $splitted_result 3]
And then I got error:
invalid command name "snmpwalk"
while executing
"snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19"
invoked from within
"array set snmp_result [snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]"
(file "./siklu.tcl" line 1)
I also learned that the tclsh is EEM policy, so I tried:
array set snmp_res [sys_reqinfo_snmp -c public -v 2c 192.168.1.20 oid .1.3.6.1.4.1.31926.2.1.1.19 get_type exact]
But that gave me this error:
invalid command name "sys_reqinfo_snmp"
while executing
"sys_reqinfo_snmp -c public -v 2c 192.168.1.20 oid .1.3.6.1.4.1.31926.2.1.1.19 get_type exact"
invoked from within
"array set snmp_res [sys_reqinfo_snmp -c public -v 2c 192.168.1.20 oid .1.3.6.1.4.1.31926.2.1.1.19 get_type axact]"
(file "./siklu.tcl" line 2)

You have to use exec command to execute them.
set snmp_result [exec snmpwalk -Os -c public -v 2c 192.168.1.20 .1.3.6.1.4.1.31926.2.1.1.19]
puts $snmp_result

Related

Github Action - Can't build gtest using ccache, mingw, cmake and ninja

I am using this workflow: cmake_build.yaml
Here is my toplevel CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(
container
VERSION 0.1.0
DESCRIPTION "An extension to the standard container library in c++"
HOMEPAGE_URL ""
LANGUAGES CXX
)
add_executable(${PROJECT_NAME} src/main.cpp)
set_target_properties(
${PROJECT_NAME}
PROPERTIES
LINKER_LANGUAGE CXX
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}"
)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
target_include_directories(
${PROJECT_NAME}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
install(
DIRECTORY
include/${PROJECT_NAME_LOWERCASE}
DESTINATION
include
)
enable_testing()
add_subdirectory(test)
and test/CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(my_project)
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 17)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_executable(
hello_test
hello_test.cc
)
target_link_libraries(
hello_test
GTest::gtest_main
)
include(GoogleTest)
gtest_discover_tests(hello_test)
I am using the example from gtest docs:
test/hello_test.cc:
#include <gtest/gtest.h>
TEST(HelloTest, BasicAssertions) {
// Expect two strings not to be equal.
EXPECT_STRNE("hello", "world");
// Expect equality.
EXPECT_EQ(7 * 6, 42);
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
It builds fine on Windows MSVC, Macos Clang, Linux GCC, but fails using Mingw GCC, here is error shown:
FAILED: test/hello_test.exe test/hello_test[1]_tests.cmake D:/a/tsst/tsst/build/test/hello_test[1]_tests.cmake
cmd.exe /C "cd . && C:\ProgramData\chocolatey\bin\g++.exe -O3 -DNDEBUG test/CMakeFiles/hello_test.dir/hello_test.cc.obj -o test\hello_test.exe -Wl,--out-implib,test\libhello_test.dll.a -Wl,--major-image-version,0,--minor-image-version,0 lib/libgtest_main.a lib/libgtest.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cmd.exe /C "cd /D D:\a\tsst\tsst\build\test && D:\a\tsst\tsst\cmake-3.24.3-windows-x86_64\bin\cmake.exe -D TEST_TARGET=hello_test -D TEST_EXECUTABLE=D:/a/tsst/tsst/build/test/hello_test.exe -D TEST_EXECUTOR= -D TEST_WORKING_DIR=D:/a/tsst/tsst/build/test -D TEST_EXTRA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX= -D TEST_SUFFIX= -D TEST_FILTER= -D NO_PRETTY_TYPES=FALSE -D NO_PRETTY_VALUES=FALSE -D TEST_LIST=hello_test_TESTS -D CTEST_FILE=D:/a/tsst/tsst/build/test/hello_test[1]_tests.cmake -D TEST_DISCOVERY_TIMEOUT=5 -D TEST_XML_OUTPUT_DIR= -P D:/a/tsst/tsst/cmake-3.24.3-windows-x86_64/share/cmake-3.24/Modules/GoogleTestAddTests.cmake""
CMake Error at D:/a/tsst/tsst/cmake-3.24.3-windows-x86_64/share/cmake-3.24/Modules/GoogleTestAddTests.cmake:112 (message):
Error running test executable.
Path: 'D:/a/tsst/tsst/build/test/hello_test.exe'
Result: Exit code 0xc0000139
Output:
Call Stack (most recent call first):
D:/a/tsst/tsst/cmake-3.24.3-windows-x86_64/share/cmake-3.24/Modules/GoogleTestAddTests.cmake:225 (gtest_discover_tests_impl)
ninja: build stopped: subcommand failed.
Build works fine without building gtest, and it fails when building test executable with gtest

Sending jq via SSH

When I running jq command locally it works:
jq --arg ip "$IP" '.nodes|.app|.ip = $ip' nodes.json
Output:
{
"nodes": 1,
"is_manager": true,
"ip": "127.0.0.1",
"cpus": 16,
"memory": 64
}
But I can't figure out how do I send it remotely via ssh, for example this command returns an error:
ssh -o StrictHostKeyChecking=no -i key.pem user#"172.13.1.23" "jq --arg ip "127.0.0.1" '.nodes|.app|.ip = $ip' nodes.json"
Output:
jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at , line 1:
.nodes|.app|.ip =
jq: 1 compile error
$ip is in double quotes, and so is expanded locally. You need to escape the dollar sign.
ssh -o StrictHostKeyChecking=no -i key.pem user#"172.13.1.23" \
"jq --arg ip "127.0.0.1" '.nodes|.app|.ip = \$ip' nodes.json"

Please tell me how to run my UEFI application on QEMU

My environment is Ubuntu15.10.
I wrote the following source code.
#include "efi.h"
#include "efilib.h"
EFI_STATUS
EFIAPI
efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
InitializeLib(ImageHandle, SystemTable);
Print(L"HelloWorld\n");
return EFI_SUCCESS;
}
I wrote the following Makefile and compile source code.
ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
OBJS = main.o
TARGET = hello.efi
EFIINC = /usr/include/efi
EFIINCS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol
EFILIB = /usr/lib
EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o
EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds
CFLAGS = $(EFIINCS) -fno-stack-protector -fpic \
-fshort-wchar -mno-red-zone -Wall
ifeq ($(ARCH),x86_64)
CFLAGS += -DEFI_FUNCTION_WRAPPER
endif
LDFLAGS = -nostdlib -znocombreloc -T $(EFI_LDS) -shared \
-Bsymbolic -L $(EFILIB) -L $(LIB) $(EFI_CRT_OBJS)
all: $(TARGET)
hello.so:$(OBJS)
ld $(LDFLAGS) $(OBJS) -o $# -lefi -lgnuefi
%.efi: %.so
objcopy -j .text -j .sdata -j .data -j .dynamic \
-j .dynsym -j .rel -j .rela -j .reloc \
--target=efi-app-$(ARCH) $^ $#
I store hello.efi on named RT directory and I run "qemu-system-x86_64 -bios OVMF.fd -hda fat:RT/".
I run hello.efi but not execute my UEFI application.
Qemu say "Error reported: Invalud Parameter".
Please help me!
Removing -L $(LIB) from the LDFLAGS in the Makefile helped:
Don't you need 'main()' vs. 'efi_main()'?

Building fiware-IoTAgent-Cplusplus from source failed due to strict-aliasing error

I'm trying to build fiware-IoTAgent-Cplusplus from source but I am getting strict-aliasing error. Any idea?
The commands I used to perform the build are as follows.
Note that I am building inside a lxc using CentOS 6.7.
$source tools/get_version_string.sh
$cmake -DGIT_VERSION=`get_rpm_version_string | cut -d ' ' -f 1` -DGIT_COMMIT=`get_rpm_version_string | cut -d
' ' -f 2` -DMQTT=ON -DCMAKE_BUILD_TYPE=Release ../../
$make
:
:
scons: done reading SConscript files.
scons: Building targets ...
g++ -o build/linux2/normal/mongo/bson/bsonelement.o -c -Wnon-virtual-dtor -Woverloaded-virtual -fPIC -ggdb -pthread -Wall -Wsign-compare -Wn
o-unknown-pragmas -Winvalid-pch -pipe -Werror -O3 -Wno-unused-function -Wno-deprecated-declarations -Wno-missing-braces -DMONGO_EXPOSE_MACRO
S -D_FILE_OFFSET_BITS=64 -DMONGO_HAVE___THREAD -DBOOST_THREAD_USES_DATETIME -DMONGO_HAVE_HEADER_UNISTD_H -DMONGO_HAVE_POSIX_MONOTONIC_CLOCK
-DMONGO_HAVE_TIMEGM -DLIBMONGOCLIENT_BUILDING -DSTATIC_LIBMONGOCLIENT -Ibuild/linux2/normal/third_party/gtest-1.7.0/include -Isrc/third_part
y/gtest-1.7.0/include -Ibuild/linux2/normal -Isrc -Ibuild/linux2/normal/mongo -Isrc/mongo -I/root/fiware/fiware-IoTAgent-Cplusplus/build/Rel
ease/third_party/boost/include -I/root/fiware/fiware-IoTAgent-Cplusplus/build/Release/third_party/boost/include src/mongo/bson/bsonelement.c
pp
cc1plus: warnings being treated as errors
In file included from /root/fiware/fiware-IoTAgent-Cplusplus/build/Release/third_party/boost/include/boost/functional/hash.hpp:6,
from src/mongo/bson/bsonelement.cpp:20:
/root/fiware/fiware-IoTAgent-Cplusplus/build/Release/third_party/boost/include/boost/functional/hash/detail/hash_float.hpp: In function 'voi
d boost::hash_combine(size_t&, const T&) [with T = double]':
/root/fiware/fiware-IoTAgent-Cplusplus/build/Release/third_party/boost/include/boost/functional/hash/detail/hash_float.hpp:71: error: derefe
rencing pointer 'ptr.266' does break strict-aliasing rules
/root/fiware/fiware-IoTAgent-Cplusplus/build/Release/third_party/boost/include/boost/functional/hash/detail/hash_float.hpp:71: note: initial
ized from here
scons: *** [build/linux2/normal/mongo/bson/bsonelement.o] Error 1
scons: building terminated because of errors.
make[2]: *** [third_party/mongo-driver/src/mongo-driver-stamp/mongo-driver-build] Error 2
make[1]: *** [CMakeFiles/mongo-driver.dir/all] Error 2
make: *** [all] Error 2
I got it. I was using a 32 bit CentOS.

Issues installing IDAS on CentOS 7 VM through provided RPMs

I've been trying to install IDAS GE in a CentOS 7 VM on my machine through the UL2.0 RPMs(download link!) available in its catalogue page.
I followed the instructions on github, but I get stuck in starting the IoT as per section 3 of the Deployment section of the instructions. If I execute the init_iotagent.sh, where I inserted the local IP of the VM, I get the error:
log4cplus:ERROR No appenders could be found for logger (main).
log4cplus:ERROR Please initialize the log4cplus system properly.
HTTPFilter DESTRUCTOR 0
HTTPFilter DESTRUCTOR 0
Also, in the instructions for Starting IoTAgent as a Service, it's said that:
After installing iot-agent-base RPM an init.d script can be found in
this folder /usr/local/iot/init.d .
But this file is not there, leading me to believe that the IoTAgent wasn't installed properly from the RPMs provided.
Also, I can't find log files regarding IoTAgent, only the MongoDB has its log file at /usr/local/iot/mongodb-linux-x86_64-2.6.9/log/mongoc.log.
If anyone could help, it would be apreciated. Also, if more info is needed, please let me know.
Thank you
I recommend you to get the GitHub repository and build the RPMs from the source and then install it in your CentOS. Like is explained in the documentation:
NOTE: I changed the BUILD_TYPE to Release, so I created the Release dir.
GIT_VERSION and GIT_COMMIT are not the latest ones.
git clone https://github.com/telefonicaid/fiware-IoTAgent-Cplusplus.git
cd fiware....
mkdir -p build/Release
cd build/Release
cmake -DGIT_VERSION=20527 -DGIT_COMMIT=217023407f25ed258043cfc00a46b6c05fb0b52c -DMQTT=ON -DCMAKE_BUILD_TYPE=Release ../../
make install
make package
The packages will be in pack/Linux/RPM/
rpm -i iot-agent-base-xxxxxxx (xxxxxxx will be the numbers of the build)
rpm -i iot-agent-ul-xxxxxx (xxxxxxx will be the numbers of the build)
Once installed with RPMs the init.d file is in: /usr/local/iot/init.d/iotagent
This is the content of the file:
#!/bin/bash
# Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
#
# This file is part of fiware-IoTagent-Cplusplus (FI-WARE project).
#
# iotagent Start/Stop iotagent
#
# chkconfig: 2345 99 60
# description: iotagent
. /etc/rc.d/init.d/functions
PARAM=$1
INSTANCE=$2
USERNAME=iotagent
EXECUTABLE=/usr/local/iot/bin/iotagent
CONFIG_PATH=/usr/local/iot/config
iotagent_start()
{
local result=0
local instance=${1}
if [[ ! -x ${EXECUTABLE} ]]; then
printf "%s\n" "Fail - missing ${EXECUTABLE} executable"
exit 1
fi
if [[ -z ${instance} ]]; then
list_instances="${CONFIG_PATH}/iotagent_*.conf"
else
list_instances="${CONFIG_PATH}/iotagent_${instance}.conf"
fi
for instance_config in ${list_instances}
do
local NAME
NAME=${instance_config%.conf}
NAME=${NAME#*iotagent_}
source ${instance_config}
local IOTAGENT_PID_FILE="/var/run/iot/iotagent_${NAME}.pid"
printf "Starting iotagent ${NAME}..."
status -p ${IOTAGENT_PID_FILE} ${EXECUTABLE} &> /dev/null
if [[ ${?} -eq 0 ]]; then
printf "%s\n" " Already running, skipping $(success)"
continue
fi
# Load the environment
set -a
source ${instance_config}
# Mandatory parameters
IOTAGENT_OPTS=" ${IS_MANAGER} \
-n ${IOTAGENT_SERVER_NAME} \
-v ${IOTAGENT_LOG_LEVEL} \
-i ${IOTAGENT_SERVER_ADDRESS} \
-p ${IOTAGENT_SERVER_PORT} \
-d ${IOTAGENT_LIBRARY_DIR} \
-c ${IOTAGENT_CONFIG_FILE}"
su ${USERNAME} -c "LD_LIBRARY_PATH=\"${IOTAGENT_LIBRARY_DIR}\" \
${EXECUTABLE} ${IOTAGENT_OPTS} & echo \$! > ${IOTAGENT_PID_FILE}" &> /dev/null
sleep 2 # wait some time to leave iotagent start
local PID=$(cat ${IOTAGENT_PID_FILE})
local var_pid=$(ps -ef | grep ${PID} | grep -v grep)
if [[ -z "${var_pid}" ]]; then
printf "%s" "pidfile not found"
printf "%s\n" "$(failure)"
exit 1
else
printf "%s\n" "$(success)"
fi
done
return ${result}
}
iotagent_stop()
{
local result=0
local iotagent_instance=${1}
if [[ -z ${iotagent_instance} ]]; then
list_run_instances="/var/run/iot/iotagent_*.pid"
else
list_run_instances="/var/run/iot/iotagent_${iotagent_instance}.pid"
fi
if [[ $(ls -l ${list_run_instances} 2> /dev/null | wc -l) -eq 0 ]]; then
printf "%s\n" "There aren't any instance of IoTAgent ${iotagent_instance} running $(success)"
return 0
fi
for run_instance in ${list_run_instances}
do
local NAME
NAME=${run_instance%.pid}
NAME=${NAME#*iotagent_}
printf "%s" "Stopping IoTAgent ${NAME}..."
local RUN_PID=$(cat ${run_instance})
kill ${RUN_PID} &> /dev/null
local KILLED_PID=$(ps -ef | grep ${RUN_PID} | grep -v grep | awk '{print $2}')
if [[ -z ${KILLED_PID} ]]; then
printf "%s\n" "$(success)"
else
printf "%s\n" "$(failure)"
result=$((${result}+1))
fi
rm -f ${run_instance} &> /dev/null
done
return ${result}
}
iotagent_status()
{
local result=0
local iotagent_instance=${1}
if [[ -z ${iotagent_instance} ]]; then
list_run_instances="/var/run/iot/iotagent_*.pid"
else
list_run_instances="/var/run/iot/iotagent_${iotagent_instance}.pid"
fi
if [[ $(ls -l ${list_run_instances} 2> /dev/null | wc -l) -eq 0 ]]; then
printf "%s\n" "There aren't any instance of IoTAgent ${iotagent_instance} running."
return 1
fi
for run_instance in ${list_run_instances}
do
local NAME
NAME=${run_instance%.pid}
NAME=${NAME#*iotagent_}
printf "%s\n" "IoTAgent ${NAME} status..."
status -p ${run_instance} ${NODE_EXEC}
result=$((${result}+${?}))
done
return ${result}
}
case ${PARAM} in
'start')
iotagent_start ${INSTANCE}
;;
'stop')
iotagent_stop ${INSTANCE}
;;
'restart')
iotagent_stop ${INSTANCE}
iotagent_start ${INSTANCE}
;;
'status')
iotagent_status ${INSTANCE}
;;
esac
And the logs file are in /tmp/ :
IoTAgent-IoTPlatform.log
IoTAgent.log
IoTAgent-Manager.log
Hope this helps you.