Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch relevant filters for ReportConfig when load functions is called. #238

Closed
snehitgajjar opened this issue Jun 17, 2016 · 16 comments
Closed
Labels

Comments

@snehitgajjar
Copy link
Contributor

If we create a ReportConfig object and add some filters to it but when I try to load same ReportConfig object using config_id it gives me back name and other information but does not return relevant filters which I added.

@sgreen-r7
Copy link
Contributor

Hi @snehitgajjar

Can you give us a little bit more info on the specifics of your use case? When I load a ReportConfig all of the filters are returning correctly (see below). Can you let us know what version of Nexpose you're using, along with the OS and the Ruby version?

It would helpful to know the exact report you're trying to use and the filters you're trying to add. Also feel free to copy/paste the script you're using and we'll be glad to be a second pair of eyes. :D

code:ruby
[3] pry(main)> report = Nexpose::ReportConfig.load nsc, 1
=> #<Nexpose::ReportConfig:0x007fc0cbbb5038
@db_export=nil,
@delivery=
#<Nexpose::Delivery:0x007fc0cbc245c8
@email=nil,
@location=nil,
@store_on_server=true>,
@filters=
[#<Nexpose::Filter:0x007fc0cbbd5338 @id="2", @type="site">,
#<Nexpose::Filter:0x007fc0cbbd50e0 @id="3", @type="site">,
#<Nexpose::Filter:0x007fc0cbbd4e88
@id="vulnerable-exploited",
@type="vuln-status">,
#<Nexpose::Filter:0x007fc0cbbd4c30
@id="vulnerable-version",
@type="vuln-status">,
#<Nexpose::Filter:0x007fc0cbbd49d8 @id="potential", @type="vuln-status">],
@Format="pdf",
@frequency=
#<Nexpose::Frequency:0x007fc0cd6315d8
@after_scan=true,
@schedule=nil,
@scheduled=false>,
@id=1,
@name="Top Remediations - 2 Sites",
@owner=1,
@template_id="prioritized-remediations",
@time_zone="America/Los_Angeles",
@users=[]>

@snehitgajjar
Copy link
Contributor Author

Nexpose Version : 4.0.5
OS : Redhat 6.5
Ruby : 2.3.0p0

Below is how I am creating and saving report.

    group_id = get_group_id(nsc, group[:name])

    report_filename = "export_#{Time.now.strftime("%Y%m%d%H%M%s")}.pdf"

    report = Nexpose::ReportConfig.new(report_filename, get_report_template_id(nsc, group[:report][:template]='Audit Report'), 'pdf')

    report.filters << Nexpose::Filter.new('group', group_id)

    group[:users].each { |user| report.users << get_user_id(nsc, user) }

    report.delivery = Nexpose::Delivery.new(true,nil, create_email)

    report.save(nsc)

Below is what I am trying to use for loading same report again

      existing_reports = @nexpose_login.list_reports

      latest_report = existing_reports.sort! { |a,b| b.generated_on <=> a.generated_on}.first

      report_config = Nexpose::ReportConfig.load(@nexpose_login, latest_report.config_id)

      puts "Object : #{report_config.name} \n Filters :#{report_config.filters}"

Which gives me output as below

     Object : export_2016061711281466180933.pdf

     Filters :[]

@gschneider-r7
Copy link
Contributor

Can you do a report.to_xml before you save it and post the (sanitized) output?

@snehitgajjar
Copy link
Contributor Author

Here is the xml,

<ReportConfig format="pdf" id="-1" name="export_2016061713331466188411.pdf" template-id="audit-report">
    <Filters>
        <filter id="135" type="group" />
    </Filters>
    <Users>
        <user id="7"/>
    </Users>
    <Delivery>
        <Storage storeOnServer="1"></Storage>
        <Email toAllAuthorized='0' sendToAclAs='file'>
            <Sender>***@****.com</Sender>
            <SmtpRelayServer>****.***.com</SmtpRelayServer>
            <Recipients></Recipients>
        </Email>
    </Delivery>
</ReportConfig>

@sgreen-r7
Copy link
Contributor

Yeah i'm not seeing the issue honestly, I just re-ran what you showed (minus the user stuff), and it worked fine for me?

code:ruby
[4] pry(main)> report_filename = "export_#{Time.now.strftime("%Y%m%d%H%M%s")}.pdf"
=> "export_2016061711371466188626.pdf"

[5] pry(main)> report = Nexpose::ReportConfig.new(report_filename, "audit-report", 'pdf')
=> #<Nexpose::ReportConfig:0x007fa59364bd98
@filters=[],
@Format="pdf",
@id=-1,
@name="export_2016061711371466188626.pdf",
@owner=nil,
@template_id="audit-report",
@time_zone=nil,
@users=[]>

[6] pry(main)> group_id = 1
=> 1
[7] pry(main)> report.filters << Nexpose::Filter.new('group', group_id)
=> [#<Nexpose::Filter:0x007fa593d14bc0 @id=1, @type="group">]

[8] pry(main)> report.save(nsc)
=> 62


Then loading:

``` code:ruby```
[9] pry(main)> report_config = Nexpose::ReportConfig.load nsc, 62
=> #<Nexpose::ReportConfig:0x007fa59488bf08
 @db_export=nil,
 @delivery=
  #<Nexpose::Delivery:0x007fa5948d1ee0
   @email=nil,
   @location=nil,
   @store_on_server=true>,
 @filters=[#<Nexpose::Filter:0x007fa59489a3f0 @id="1", @type="group">],
 @format="pdf",
 @frequency=
  #<Nexpose::Frequency:0x007fa5948b1f78
   @after_scan=false,
   @schedule=nil,
   @scheduled=false>,
 @id=62,
 @name="export_2016061711371466188626.pdf",
 @owner=1,
 @template_id="audit-report",
 @time_zone="America/Los_Angeles",
 @users=[]>

[10] pry(main)> puts "Object : #{report_config.name} \n Filters :#{report_config.filters}"
Object : export_2016061711371466188626.pdf
 Filters :[#<Nexpose::Filter:0x007fa59489a3f0 @type="group", @id="1">]

@sgreen-r7
Copy link
Contributor

Can you try seeing what happens if you don't include the following during creation?

code:ruby
group[:users].each { |user| report.users << get_user_id(nsc, user) }
report.delivery = Nexpose::Delivery.new(true,nil, create_email)

@snehitgajjar
Copy link
Contributor Author

Ok so when I commented above two lines. Now it is showing me filters. So is it expected behavior?

@sgreen-r7
Copy link
Contributor

@snehitgajjar no, it's not expected behavior :)

I think it's breaking when adding a delivery option, can you try adding users, then load the report and see if filters are there? then if that works, try adding a delivery object.

also can you show me what the create_email method is creating? or just list out your full report object prior to hitting save?

@snehitgajjar
Copy link
Contributor Author

snehitgajjar commented Jun 17, 2016

Report object before saving (Users are added but Delivery is commented out):

<ReportConfig format="pdf" id="-1" name="export_2016061715441466196241.pdf" template-id="audit-report">
    <Filters>
        <filter id="138" type="group" />
    </Filters>
    <Users>
        <user id="7"/>
    </Users>
</ReportConfig>

Report config after loading (Filters are blank):

<ReportConfig format="pdf" id="84" name="export_2016061715441466196241.pdf" template-id="audit-report" owner="4" timezone="America/Chicago">
    <Filters></Filters>
    <Users>
        <user id="7"/>
    </Users>
    <Generate after-scan="0" schedule="0"></Generate>
    <Delivery>
        <Storage storeOnServer="1"></Storage>
    </Delivery>
</ReportConfig>

Function 'create_email' :

  def self.create_email
    email = Nexpose::Email.new(0, nil, 'file', nil)

    email.sender = 'nexpose@cerner.com'

    email.smtp_relay_server = 'email.com'

    return email
  rescue  Nexpose::APIError => error
    raise "Error occured while creating email #{error}"
  end

@sgreen-r7
Copy link
Contributor

okay. did saving and loading with just the users work?

@snehitgajjar
Copy link
Contributor Author

It was just with users it returns nil filters. So if I use Delivery or User or Both, it returns Empty Filters.

@gschneider-r7
Copy link
Contributor

After loading the report config, do @nexpose_login.response_xml and post the (sanitized) output. Curious if the XML response itself is missing filters, or if parsing it in Ruby has a problem.

@snehitgajjar
Copy link
Contributor Author

OUTPUT FOR @nexpose_login.response_xml :

<ReportConfigResponse success="1">
    <ReportConfig id="*" name="export_2016061716171466198238.pdf" template-id="audit-report" format="pdf" owner="*" timezone="****/***">
        <Filters></Filters>
        <Generate after-scan="0" schedule="0"/>
        <Users></Users>
        <Delivery>
            <Storage storeOnServer="1"/>
            <Email sendToAclAs="file" toAllAuthorized="0">
                <Recipients></Recipients>
                <SmtpRelayServer>**.****.com</SmtpRelayServer>
                <Sender>**@***.com</Sender>
            </Email>
        </Delivery>
    </ReportConfig>
</ReportConfigResponse>

@sgreen-r7
Copy link
Contributor

@snehitgajjar just as a heads up, we have not be able to reproduce your issue, but we're still working on trying to figure it out.

In the meantime, you could possibly just have your script save the config with the filters and without the users and delivery options. Then reload the config and add the users and delivery options. Hopefully that will get functional (although not an awesome workaround).

Let us know if you have any additional info to add.

@sgreen-r7 sgreen-r7 added the Bug label Jun 21, 2016
@snehitgajjar
Copy link
Contributor Author

@sgreen-r7 Thank you for looking into it. I will use workaround on this one until it's been fixed. I will post if there is additional information.

@gschneider-r7
Copy link
Contributor

Closing this out since we could not reproduce the issue. Feel free to re-open or open a new issue if you have anything new on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants