Puppet have a defined resource fail if a variable is set to undef - puppet

I am writing a puppet defined type as follows:
1 #--------------------------------------------------#
2 #-------------------WindowsLog---------------------#
3 #--------------------------------------------------#
4 # Type to set up a windows log #
5 #--------------------------------------------------#
6
7 define windows_log($size = '25MB', $overflowAction = 'OverwriteAsNeeded', $logName = $title)
8 {
9
10 #Microsoft is stupid. Get-WinEvent has different names for logmode than limit-eventlog.
11 #The following selector (basuically a ternary operator) should fix that
12 $overflowWinEventName = $overflowAction ? {
13 OverwriteAsNeeded => "Circular",
14 OverwriteOlder => "AutoBackup",
15 DoNotOverwrite => "Retain",
16 default => undef,
17 }
18
19 if($overflowWinEventName == undef)
20 {
21 fail("${$overflowAction} is not a valid overflow action")
22 }
23 else{
24 exec { "Set maximum log size for ${logName}":
25 provider => powershell,
26 command => "Limit-EventLog -LogName ${logName} -MaximumSize ${size} -OverflowAction ${overflowAction}",
27 unless => "\$log = Get-WinEvent -ListLog ${logName}; if(\$log.MaximumSizeInBytes -eq ${size} -and \$log.LogMode -eq '${overflowWinEventName}'){exit 0}else{exit 1}",
28 }
29 }
30 }
However the method 'fail' does not have the effect I want, and none of the methods listed at http://docs.puppetlabs.com/references/latest/function.html seem to be right either.
Basically I am trying to get puppet to throw an error for this specific resource only, stop applying it, and then continue applying everything else. Fail throws a parser error which kills everything, and the other methods (warn, error, etc) seem to have no effect on the agent.
Any help would be greatly appreciated! I may have just stupidly overlooked something.

Your construct is basically sound. Defined resources cannot really 'fail' like native resources, but using your if/else construct, it will only do any work if there is no error.
Use fail() only if you detect an error that should make the whole catalog invalid. To just send a message to the agent, use a notify resource instead.
notify {
"FATAL - ${overflowAction} is not a valid overflow action":
loglevel => 'err',
withpath => true; # <- include the fully qualified resource name
}

Related

Why isn't Jest applying my timeout when I use jest.setTimeout()? [duplicate]

This question already has answers here:
How can I increase the test time out value in jest?
(3 answers)
Closed 9 months ago.
I know I can use jest.setTimeout() to set a custom timeout for a test. I'm doing this below. MINUTE has the value 60 * 1000.
Why isn't Jest applying my timeout?
thrown: "Exceeded timeout of 5000 ms for a test.
Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
13 |
14 | describe(`integration with API provider`, () => {
> 15 | it(`works`, async () => {
| ^
16 | // Just in case network is slow.
17 | jest.setTimeout(1 * MINUTE);
As you've seen (and despite what's claimed elsewhere on SO), you cannot change a single test's timeout by calling jest.setTimeout from inside it. Note that the docs you quote state (emphasis mine):
This only affects the test file from which this function is called.
It's intended to be used at test discovery time, not execution time, to set the timeout for a given context. The timeout is set before the test callback is invoked, you can't change it once the test actually starts.
For a single test you can set the timeout by passing a third argument to the test/it function (or the various helpers defined on it), for example:
it("has a description", () => {
// ...
}, 60_000);

Logstash convert date duration from string to hours

I have a column like this:
business_time_left
3 Hours 24 Minutes
59 Minutes
4 Days 23 Hours 58 Minutes
0 Seconds
1 Hour
and so on..
What I want to do in Logstash is to convert this entirely into hours.
So mu value should entirety convert to something like
business_time_left
3.24
0.59
119.58
0
1
Is this possible?
My config file:
http_poller {
urls => {
snowinc => {
url => "https://service-now.com"
user => "your_user"
password => "yourpassword"
headers => {Accept => "application/json"}
}
}
request_timeout => 60
metadata_target => "http_poller_metadata"
schedule => { cron => "* * * * * UTC"}
codec => "json"
}
}
filter
{
json {source => "result" }
split{ field => ["result"] }
}
output {
elasticsearch {
hosts => ["yourelastuicIP"]
index => "inc"
action=>update
document_id => "%{[result][number]}"
doc_as_upsert =>true
}
stdout { codec => rubydebug }
}
Sample Json input data, when the url is hit.
{"result":[
{
"made_sla":"true",
"Type":"incident resolution p3",
"sys_updated_on":"2019-12-23 05:00:00"
"business_time_left":" 59 Minutes"} ,
{
"made_sla":"true",
"Type":"incident resolution l1.5 p4",
"sys_updated_on":"2019-12-24 07:00:00"
"business_time_left":"3 Hours 24 Minutes"}]}
Thanks in advance!
Q: Is this possible?
A: Yes.
Assuming your json- and split-filters are working correctly and the field business_time_left holds a single value like you showed (e.g. 4 Days 23 Hours 58 Minutes) I personally would do the following:
First, make sure that your data is in a kind of pattern meaning, you standardize the "quantity-descriptions". This means that the minutes are always labeled as "Minutes" not Mins, min or whatever.
Nextup, you can parse the field with the grok-filter like so:
filter{
grok{
match => { "business_time_left" => "(%{INT:calc.days}\s+Days)?%{SPACE}?(%{INT:calc.hours}\s+Hours)?%{SPACE}?(%{INT:calc.minutes}\s+Minutes)?%{SPACE}?(%{INT:calc.seconds}\s+Seconds)?%{SPACE}?" }
}
}
This will extract all available values into the desired fields, e.g. calc.days. The ? character prevents that grok fails if e.g. there are no seconds. You can test the pattern on this site.
With the data extracted, you can implement a ruby filter to aggregate the numeric values like so (untested though):
ruby{
code => '
days = event.get("calc.days")
hours = event.get("calc.hours")
minutes = event.get("calc.minutes")
sum = 0
if days
days_numeric = days.to_i
days_as_hours = days_numeric * 24
sum += days_as_hours
end
if hours
sum += hours.to_i
end
if minutes
sum += (minutes.to_i / 100)
end
# seconds and so on ...
event.set("business_time_left_as_hours", sum)
'
}
So basically you check if the values are present and add them to a sum with your custom logic.
event.set("business_time_left_as_hours", sum) will set the result as a new field to the document.
These code snippets are not intended to be working out of the box they are just hints. So please check the documentations about the ruby filter, ruby coding in general and so on.
I hope I could help you.

gtk_css_value_inherit_free: code should not be reached

I making one plugin with Python for Rhythmbox.
I get an randomly error when start the plugin. Then of some seconds I reset Rhythmbox and the plugin run ok.
What will the cases that probably originy the error?
Error:
gtkcssinheritvalue.c:33:gtk_css_value_inherit_free: code should not be reached
gtkcssinheritvalue.c:
29 static void
30 gtk_css_value_inherit_free (GtkCssValue *value)
31 {
32 /* Can only happen if the unique value gets unreffed too often */
33 g_assert_not_reached ();
34 }
https://github.com/GNOME/gtk/blob/gtk-3-6/gtk/gtkcssinheritvalue.c
All suggestion is welcome. Thanks.

How to programmatically query senderbase.org?

I'm trying to programmatically query senderbase.org but it's really hard to find any information about it.
I tried to query with:
dig txt 8.8.8.8.query.senderbase.org
Which returns:
"0-0=1|1=Google Incorporated|2=3.7|3=4.0|4=3228772|6=1174353533|8=2880|9=1|20=google-public-dns-a.|21=google.com|22=Y|23=7.9|24=8.0|25=1049184000|40=3.7|41=4.0|43=3.8|44=0.06|45=N|46=24|48=24|49=1.00|50=Mountain View|51=CA|52=94043|53=US|54=-122.057|"
But none of these fields seems to indicate if the IP is listed or not.
I found the following page with a description of the fields. But field 26, which seems to be what i need, is not present ( http://web.archive.org/web/20040830010414/http://www.senderbase.org/dnsresponses.html ).
I also found some SpamAssassin extensions which were querying rf.senderbase.org but it gives me inconsistent results. For the same field, sometimes it returns a float and sometimes it doesn't return anything.
Any ideas? Or parsing their html is the only option?
Thanks.
The key values are as follows
'0-0' => 'version_number',
1 => 'org_name',
2 => 'org_daily_magnitude',
3 => 'org_monthly_magnitude',
4 => 'org_id',
5 => 'org_category',
6 => 'org_first_message',
7 => 'org_domains_count',
8 => 'org_ip_controlled_count',
9 => 'org_ip_used_count',
10 => 'org_fortune_1000',
20 => 'hostname',
21 => 'domain_name',
22 => 'hostname_matches_ip',
23 => 'domain_daily_magnitude',
24 => 'domain_monthly_magnitude',
25 => 'domain_first_message',
26 => 'domain_rating',
40 => 'ip_daily_magnitude',
41 => 'ip_monthly_magnitude',
43 => 'ip_average_magnitude',
44 => 'ip_30_day_volume_percent',
45 => 'ip_in_bonded_sender',
46 => 'ip_cidr_range',
47 => 'ip_blacklist_score',
50 => 'ip_city',
51 => 'ip_state',
52 => 'ip_postal_code',
53 => 'ip_country',
54 => 'ip_longitude',
55 => 'ip_latitude',
The "domain rating" specified in SenderBase DNS responses is something that was implemented but never utilized, or at least not enough to make it useful. Other fields that were originally specified are a little hit-or-miss as well, although most should be pretty fresh for higher-volume senders of email. You might want to check out the Perl Net::SenderBase library, either to use it directly or as a reference for your own implementation.
The rf.senderbase.org domain you referred to reflects SenderBase Reputation Scores (SBRS), which is mostly independent from what you see on http://www.senderbase.org. SBRS is not considered a public service, so it would be wise to receive permission from Cisco/IronPort before using it for anything serious.

Components.interfaces.nsIProcess2 in Firefox 3.6 -- where did it go?

I am beta testing an application that includes a Firefox extension as one component. It was originally deployed when FF3.5.5 was the latest version, and survived 3.5.6 and 3.5.7. However on FF3.6 I'm getting the following in my error console:
Warning: reference to undefined property Components.interfaces.nsIProcess2
Source file: chrome://overthewall/content/otwhelper.js
Line: 55
Error: Component returned failure code: 0x80570018 (NS_ERROR_XPC_BAD_IID)
[nsIJSCID.createInstance]
Source file: chrome://overthewall/content/otwhelper.js
Line: 55
The function throwing the error is:
48 function otwRunHelper(cmd, aCallback) {
49 var file =
50 Components.classes["#mozilla.org/file/local;1"].
51 createInstance(Components.interfaces.nsILocalFile);
52 file.initWithPath(otwRegInstallDir+'otwhelper.exe');
53
54 otwProcess = Components.classes["#mozilla.org/process/util;1"]
55 .createInstance(Components.interfaces.nsIProcess2);
56
57 otwProcess.init(file);
58 var params = new Array();
59 params = cmd.split(' ');
60
61 otwNextCallback = aCallback;
62 otwObserver = new otwHelperProcess();
63 otwProcess.runAsync(params, params.length, otwObserver, false);
64 }
As you can see, all this function does is run an external EXE helper file (located by a registry key) with some command line parameters and sets up an Observer to asynchronously wait for a response and process the Exit code.
The offending line implies that Components.interfaces.nsIProcess2 is no longer defined in FF3.6. Where did it go? I can't find anything in the Mozilla documentation indicating that it has been changed in the latest release.
The method on nsIProcess2 was moved to nsIProcess. For your code to work in both versions, change this line:
otwProcess = Components.classes["#mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess2);
to this:
otwProcess = Components.classes["#mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess2 || Components.interfaces.nsIProcess);
You will still get the warning, but the error will go away, and your code will work just fine in both versions. You could also store the interface iid in a variable and use the variable:
let iid = ("nsIProcess2" in Components.interfaces) ?
Components.interfaces.nsIProcess2 :
Components.interfaces.nsIProcess;
otwProcess = Components.classes["#mozilla.org/process/util;1"]
.createInstance(iid);

Resources