ambitious-wmi

25 views
Skip to first unread message

Gordon Thiesfeld

unread,
Mar 3, 2008, 7:08:24 PM3/3/08
to ambition.rb
I've been working on an adapter for WMI (Windows Management
Instrumentation). It's built on top of my ruby-wmi gem, which is very
similar to ActiveRecord. WMI uses a subset of SQL (called WQL) for
it's queries, so a lot of my code is borrowed heavily from ambitious-
activerecord. I've been at it for a few days, and things are going
pretty well. I do have a few questions, though.

Ambition require ParseTree 2.0.1, but it doesn't work so well on
windows. I changed it to 2.1.1 and it seems to be working just fine.
Any chance of updating to that in the next release? It's no big deal
for my adapter. Ruby-wmi has been dowloaded a whopping 24 times, so
I'm not setting the world on fire. It would probably help for
ambition adoption on windows, though.

Also, I did a windows event log query that looked like this:

start = Time.local(2008,3,2).to_swebmDateTime
stop = Time.local(2008,3,3).to_swebmDateTime

events = WMI::Win32_NTLogEvent.select{ |e|
e.timewritten >= start && e.timewritten < stop
}

But, I thought I'd like it to look like this:

range = start..stop
events = WMI::Win32_NTLogEvent.select{ |e| range.include?
e.timewritten }

and produce this query:
"SELECT * FROM Win32_NTLogEvent WHERE (timewritten >=
'20080302000000.000000-360' AND timewritten <
'20080303000000.000000-360')"

I've actually written the code to wire this up. I can't see any
reason not to do this, but I'm certainly no expert. I'd like to hear
other opinions.

Thanks,

Gordon

Gordon Thiesfeld

unread,
Mar 3, 2008, 11:06:53 PM3/3/08
to ambition.rb


On Mar 3, 6:08 pm, Gordon Thiesfeld <gthiesf...@gmail.com> wrote:

> But, I thought I'd like it to look like this:
>
> range = start..stop
> events = WMI::Win32_NTLogEvent.select{ |e| range.include?
> e.timewritten }
>
> and produce this query:
> "SELECT * FROM Win32_NTLogEvent WHERE (timewritten >=
> '20080302000000.000000-360' AND timewritten <
> '20080303000000.000000-360')"
>
> I've actually written the code to wire this up. I can't see any
> reason not to do this, but I'm certainly no expert. I'd like to hear
> other opinions.

OK, I forgot to take into account the 2 dot or 3 dot ranges (include
exclude end). Here are my updated specs:

specify "range: (lo..hi).include? item" do
lo = 3
hi = 5
wql = @klass.select { |m| (lo..hi).include? m.drivetype }
wql.to_s.should == "SELECT * FROM Win32_LogicalDisk WHERE
(drivetype >= '3' AND drivetype <= '5')"
end


specify "range: (lo...hi).include? item" do
lo = 3
hi = 5
wql = @klass.select { |m| (lo...hi).include? m.drivetype }
wql.to_s.should == "SELECT * FROM Win32_LogicalDisk WHERE
(drivetype >= '3' AND drivetype < '5')"
end

Chris Wanstrath

unread,
May 2, 2008, 2:14:34 PM5/2/08
to ambit...@googlegroups.com
Ambition should be on the newest ParseTree now.

- Chris

--
Chris Wanstrath
http://github.com/defunkt

Gordon Thiesfeld

unread,
May 2, 2008, 3:04:28 PM5/2/08
to ambit...@googlegroups.com
On Fri, May 2, 2008 at 1:14 PM, Chris Wanstrath <ch...@ozmm.org> wrote:
>
> Ambition should be on the newest ParseTree now.
>
> - Chris
>

Yep. I've been following along on GitHub. I (vertiginous) sent you a
pull request earlier today to add processors for ranges. I'm
interested to hear what you think.

Gordon

Reply all
Reply to author
Forward
0 new messages