What file format is this? ( Used for a perl script status ) - perl

I am trying to find out what format status file in nagios is, it has a .dat extention but is not the standard .dat ( at least not the windows .dat )
Here is an example of the format
contactstatus {
contact_name=noc
modified_attributes=0
modified_host_attributes=0
modified_service_attributes=0
host_notification_period=24x7
service_notification_period=24x7
last_host_notification=0
last_service_notification=1545078717
host_notifications_enabled=1
service_notifications_enabled=1
}
contactstatus {
contact_name=slack
modified_attributes=0
modified_host_attributes=0
modified_service_attributes=0
host_notification_period=24x7
service_notification_period=24x7
last_host_notification=0
last_service_notification=1545078717
host_notifications_enabled=1
service_notifications_enabled=1
}

Found that it is not a standard, but a nagios custom format

Related

Cake Task output log to file

I have a set of Tasks inside a build.cake file and I would like to capture the log output from the console into a log file. I know it's possible to use the OnError() function to output errors to file but I would like to output everything to a log file, not just errors.
Below is an example of the build.cake file.
#load "SomeTask.cake"
#load "SomeOtherTask.cake"
var target = Argument("target", "Default");
var someTask = Task("SomeTask")
.Does(() =>
{
SomeMethodInsideSomeTask();
});
var someOtherTask = Task("SomeOtherTask")
.Does(() =>
{
SomeOtherMethodInsideSomeOtherTask();
});
Task("Default")
.IsDependentOn(someTask)
.IsDependentOn(someOtherTask);
RunTarget(target);
N.B. The Tasks are not running any sort of MSBuild commands so it's not possible to use MSBuildFileLogger.
How about pipe the stdout to a file i.e.
./build.ps1 > log.txt
Have you heard about tee ?
It reads standard input and writes it to both standard output and one or more files

how to read aparticular line from log file using logstash

I have to read 3 different lines from log files based on some text and then output the fields in a csv file.
sample log data:-
20110607 095826 [.] !! Begin test. Script filename/text.txt
20110607 095826 [.] Full path: filename/test/text.txt
20110607 095828 [.] FAILED: Test Failed()..
i have to read file name after !!Begin test. Script. this is my conf file
filter{
grok
{
match => {"message" => "%{BASE10NUM:Date}%{SPACE:pat}{BASE10NUM:Number}%
{SPACE:pat}[.]%{SPACE:pat}%{SPACE:pat}!! Begin test. Script%
{SPACE:pat}%{GREEDYDATA:file}"
}
overwrite => ["message"]
}
if "_grokparserfailure" in [tags]
{
drop{}
}
}
but its not giving me single record, its parsing full log file in json format no parsed field.

logstash(2.3.2) gzip codec not work

I'm using logstash(2.3.2) to read gz file by using gzip_lines codec.
The log file example (sample.log) is
127.0.0.2 - - [11/Dec/2013:00:01:45 -0800] "GET /xampp/status.php HTTP/1.1" 200 3891 "http://cadenza/xampp/navi.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0"
The command I used to append to a gz file is:
cat sample.log | gzip -c >> s.gz
The logstash.conf is
input {
file {
path => "./logstash-2.3.2/bin/s.gz"
codec => gzip_lines { charset => "ISO-8859-1"}
}
}
filter {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
#match => { "message" => "message: %{GREEDYDATA}" }
}
#date {
# match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
#}
}
output {
stdout { codec => rubydebug }
}
I have installed gzip_line plugin with bin/logstash-plugin install logstash-codec-gzip_lines
start logstash with ./logstash -f logstash.conf
When I feed s.gz with
cat sample.log | gzip -c >> s.gz
I expect that the console prints the data. but there is nothing print out.
I have tried it on mac and ubuntu, and get same result.
Is anything wrong with my code?
I checked the code for gzip_lines and it seemed obvious to me that this plugin is not working. At least for version 2.3.2. May be it is outdated. Because it does not implement the methods specified here:
https://www.elastic.co/guide/en/logstash/2.3/_how_to_write_a_logstash_codec_plugin.html
So current internal working is like that:
file input plugin reads file line by line and send it to codec.
gzip_lines codec tryies to create a new GzipReader object with GzipReader.new(io)
It then go through the reader line by line to create events.
Because you specify a gzip file, file input plugin tries to read gzip file as a regular file and sends lines to codec. Codec tries to create a GzipReader with that string and it fails.
You can modify it to work like that:
Create a file that contains list of gzip files:
-- list.txt
/path/to/gzip/s.gz
Give it to file input plugin:
file {
path => "/path/to/list/list.txt"
codec => gzip_lines { charset => "ISO-8859-1"}
}
Changes are:
Open vendor/bundle/jruby/1.9/gems/logstash-codec-gzip_lines-2.0.4/lib/logstash/codecs/gzip_lines.r file. Add register method:
public
def register
#converter = LogStash::Util::Charset.new(#charset)
#converter.logger = #logger
end
And in method decode change:
#decoder = Zlib::GzipReader.new(data)
as
#decoder = Zlib::GzipReader.open(data)
The disadvantage of this approach is it wont tail your gzip file but the list file. So you will need to create a new gzip file and append it to list.
I had a variant of this problem where I needed to decode bytes in a files to an intermediate string to prepare for a process input that only accepts strings.
The fact that encoding / decoding issues were ignored in Pyhton 2 is actually really bad IMHO. you may end up with various corrupt data problems especially if you needed to re-encode the string back into data.
using ISO-8859-1 works for both gz and text files alike. while utf-8 only worked for text files. I haven't tried it for png's yet.
Here's an example of what worked for me
data = os.read(src, bytes_needed)
chunk += codecs.decode(data,'ISO-8859-1')
# do the needful with the chunk....

Upload a video captions file to Facebook?

According to Facebook's documentation and this bug report the contents of the .srt file should be in the captions_file parameter. I have tried doing this, but continue to get the error:
facebookSDK.GraphAPIError: (#100) Invalid file. Expected file of one of the following types: application/octet-stream
This is the same error Facebook user Ravi mentions in the bug report. What am I doing wrong? Do the file contents need to be converted to binary? Does a Content-Type:application/octet-stream header need to be added? What specifically needs to be sent via HTTP request?
I had the same issue - used the Facebook's SDK for PHP this is actually a bug in the Facebook SDK , solved it by extending the FacebookFile class used for upload
I use the following when trying to upload a captions file :
class FacebookCaptionsFile extends \Facebook\FileUpload\FacebookFile
{
/**
* override the original method since srt is not amongst the known file types in the facebook Mimetypes
*/
public function getMimetype()
{
return 'application/octet-stream';
}
}
and the call :
public static function uploadCaptions($appId, $appSecret, $accessToken, $videoId, $filePath, $locale)
{
if (!file_exists($filePath))
throw new Exception("Captions file given does not exist: ".$filePath);
//create file name in format: filename.locale.srt
$newFilePath = basename($filePath, '.'.pathinfo($filePath, PATHINFO_EXTENSION)).'.'.$locale.'.srt';
copy($filePath, $newFilePath);
$data = array (
'captions_file' => new FacebookCaptionsFile($newFilePath),
);
self::helperChangeVideo($appId, $appSecret, $accessToken, $data, $videoId, false, "/captions" );
}
I logged a bug to Facebook about this and the solution was to use locally stored file instead of URL. For example:
curl -i -X POST -F "captions_file=#\"subs.bg_BG.srt\"" https://graph.facebook.com/v2.7/***/captions?access_token...

Reading line containing multiple XML tags

I have a text file containing lines with multiple xml tags in single line.Below is the sample of it (returns and spacing added for clarity).
xmlns="http://www.opentravel.org/OTA/2003/05" EchoToken="1397133927.05244" TimeStamp="2014-04-10T07:45:27.00-05:00" Target="Production" Version="1.002" PrimaryLangID="en-us"><POS><Source><RequestorID Type="18" ID="HILTON"/></Source></POS><AvailStatusMessages ChainCode="ES" BrandCode="ES" HotelCode="41914">
<AvailStatusMessage><StatusApplicationControl Start="2014-04-20" End="2014-04-26" Sun="1" InvCodeApplication="InvCode" InvCode="U1K" RatePlanCodeType="RatePlanCode" RatePlanCode="EXL" RateTier="8" IsRoom="1" Override="1"/><LengthsOfStay ArrivalDateBased="1" FixedPatternLength="2"><LengthOfStay Time="1" TimeUnit="Day" MinMaxMessageType="FullPatternLOS"/></LengthsOfStay></AvailStatusMessage>
<AvailStatusMessage><StatusApplicationControl Start="2014-04-20" End="2014-04-26" Mon="1" Tue="1" Weds="1" Thur="1" Fri="1" Sat="1" InvCodeApplication="InvCode" InvCode="U1K" RatePlanCodeType="RatePlanCode" RatePlanCode="EXL" RateTier="8" IsRoom="1" Override="1"/><LengthsOfStay ArrivalDateBased="1" FixedPatternLength="1"></LengthsOfStay></AvailStatusMessage>
<AvailStatusMessage><StatusApplicationControl Start="2014-04-27" End="2014-05-21" Sun="1" Mon="1" Tue="1" Weds="1" Thur="1" Fri="1" Sat="1" InvCodeApplication="InvCode" InvCode="U1K" RatePlanCodeType="RatePlanCode" RatePlanCode="EXL" RateTier="8" IsRoom="1" Override="1"/><LengthsOfStay ArrivalDateBased="1"
I have tag , which contains field with StatusApplicationControl Start value . I want to get all such AvailStatusMessage tags which have StatusApplicationControl start value as "2014-04-27".
Please assist me of getting this done using perl or shell script.
Thanks in advance.
You could try the following code:
#! /usr/bin/perl
use v5.12;
use File::Slurp;
my $txt=read_file('file');
while ($txt=~m{<AvailStatusMessage>(.*?)</AvailStatusMessage>}gms) {
my $atxt=$1;
if ($atxt=~m{<StatusApplicationControl (.*?)/>}ms) {
my $tmp=$1;
if ($tmp=~m{Start="2014-04-27"}ms) {
say $atxt;
}
}
}