syslog-ng return original value when mapping does not exists - syslog

i'm using syslog-ng for collecting json messages and send alarms to slack
there is parameter in json message which contains IP address of router from which I'm receiving the json message and I want to convert IP address to router hostname
i'm using two parsers 1) parse json 2) replace IP address with router hostname:
parser p_json {
json-parser(prefix(".json."));
};
parser p_acd_router {
add-contextual-data(selector("${.json.router_ip}"), database("host_map.csv"), prefix(".meta_router."));
};
until now everything works fine.
Hi,
I'm having the problem when I receive log message from router and I don't have IP_to_Hostname mapping for it in csv file. in this case i just get blank space in syslog message. there is option to return default value if mapping does not exist, but i would prefer to return original value (IP address)
if mapping exists convert IP address to hostname >> works
if mapping does not exist, return original IP address >> don't know how to set it up
is this even supported?
thanks

You can set the default-selector("UNKNOWN") option for add-contextual-data(), and add a record to your CSV file with the ID UNKNOWN, and use the following value when setting .meta_router.hostname: ${.json.router_ip}.
TLDR: templates are supported inside the CSV file as well.
Note: In case your IPs are reverse-resolvable, you can just use the $(dns-resolve-ip) template function instead of maintaining a complete CSV database:
https://github.com/syslog-ng/syslog-ng/pull/3046

Related

In Corda how can we get the Node database connection string in the API

I am trying to get the the JDBCsession connection url from the node into my API using a flow. I could get the flow to return the url using serviceHub.jdbcSession().metaData.url. However this returns url of the form "jdbc:h2:file:D:\Anshulee Projects\Corda\XXX-corda-network\build\nodes\Provider/persistence" and while a query using serviceHub.jdbcSession within the node works well, any attempt to connect to this url via the h2 Console or another created JDBCSession etc results in a Database in use exception. How can i get the the same connection string as seen in the crash shell? This one jdbc:h2:tcp://172.18.148.97:9190/node?
There is no method to retrieve the JDBC TCP connection string.
However, you can statically set the node's H2 address and port in the node's node.conf file, and use these static values for the frontend.
As of Corda 3, you configure this in the node.conf file using:
h2port=12345
In Corda 4, the configuration option will have changed to:
h2Settings { address: "localhost:12345" }

gRPC in Java - How to recieve file content as response

I'm new to gRPC programming. I need to write a gRPC client which receives file content sent from the gRPC server and send this content to web-page. As the file content is huge, I've set it as a stream.
Below is my .proto file
service LogService {
rpc fetchLogContent(LogRequest) returns (stream LogResponse);
}
message LogRequest {
string ip = 1;
string fileName = 2;
}
message LogResponse {
string ip = 1;
string logContent = 2;
}
Now, in the client, when I use the blockingStub to access fetchLogContent, it returns an Iterator . I understand from the examples provided grpc.io - java, if there are list of response objects, (list of Feature objects in the example provided in link), an Iterator will be valid. But in my case, I need a single LogResponse which was sent as a stream. Please provide any suggestions/alternatives for this. Thanks in advance. :)
In your Method definition:
rpc fetchLogContent(LogRequest) returns (stream LogResponse);
The stream keyword means that you will get 0 or more LogResponse messages. If the content is very large, what you can do is read chunks of the file (like 4kb) and send multiple LogResponse messages each with a part of the file. The client side can read the chunks repeatedly, and piece it back together.
Since the ip field will likely not be changing each time, you can make you server only set ip on the first message. On the client, just use the very first ip received.

How do I send a file through a send port with the same name as the FileReceiveName in BiztalkAdministrationConsole?

I receive an email with an attached file.
I retrieve the email through a receive location.
Retrieve the attachment through a pipeline.
Then I have a send Port that consumes the message from the pipeline.
I'd like the send port to publish the document with the same name the file had in the attachment.
I read that you had to use the macro %SourceFileName% when setting the file name in the send port configurations.
I tried that but the file name comes out as literally %SourceFileName%.
I stopped the send port to check what was the FileReceivedName and it is what I want.
These are the Send Port Configurations.
After I restart the send port the file that gets published.
You can promote a context property(nor especially ReceivedFileName) in your pipeline and use a macro to get this property like what you did with ReceivedFileName. have a look on this thread:
%SourceFileName% is macro for the FILE.ReceivedFileName message context property which is normally added to the message context by FILE or FTP adapter, but not SMTP. You can set this property yourself inside orchestration or your receive pipeline and then you will be able to use the %SourceFileName% macro on the send port.
Get the attachment filename from mime-properties and promote ReceivedFileName property to get %SourceFileName% during sending.
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg) {
IBaseMessagePart bodyPart = pInMsg.BodyPart;
if (bodyPart != null)
{
string fileName = (string)pInMsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties");
fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
pInMsg.BodyPart.PartProperties.Write("FileName", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", fileName);
}
return pInMsg;}

Poco HTTPSClient session by IP address

I'm trying to use Poco HTTPS client session to download a site from hostname by specific IP address.
For example, google.com has the following addresses:
173.194.221.113
173.194.221.138
173.194.221.102
173.194.221.139
173.194.221.100
173.194.221.101
I want to get https://google.com via 173.194.221.102
I was trying the following approach:
std::make_unique<HTTPSClientSession>(SecureStreamSocket(SocketAddress(IPAddress("173.194.221.102"), 0), "https://google.com"));
This fails with the exception "Illegal state: Cannot set the port number for an already connected session"
Looking at the Poco source code, the SecureStreamSocket created with this constructor is connected, and the constructor of HTTPSClientSession tries to set the https port(443), and fails to do that with the already connected socket.
Any better way to do that?
Should be something like that:
Poco::Net::initializeSSL();
Poco::Net::HTTPSessionFactory::defaultFactory().registerProtocol("https", new Poco::Net::HTTPSSessionInstantiator);
const Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> certificateHandler(new Poco::Net::AcceptCertificateHandler(false));
const Poco::Net::Context::Ptr context(new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, ""));
Poco::Net::SSLManager::instance().initializeClient(nullptr, certificateHandler, context);
Poco::URI serverUri("your address");
Poco::Net::HTTPClientSession* session = Poco::Net::HTTPSessionFactory::defaultFactory().createClientSession(serverUri);
Hope it helps.

R Change IP Address programmatically

Currently changing user_agent by passing different strings to the html_session() method.
Is there also a way to change your IP address on a timer when scraping a website?
You can use a proxy (which changes your ip) via use_proxy as follows:
html_session("you-url", use_proxy("proxy-ip", port))
For more details see: ?httr::use_proxy
To check if it is working you can do the following:
require(httr)
content(GET("https://ifconfig.co/json"), "parsed")
content(GET("https://ifconfig.co/json", use_proxy("138.201.63.123", 31288)), "parsed")
The first call will return your IP. The second call should return 138.201.63.123 as ip.
This Proxy was taken from http://proxylist.hidemyass.com/ - no garantees for anything...

Resources