I am currently talking to ConsoleKit with GDBus. I used the ConsoleKit2 XML files and gdbus-codegen to generate the code. Everything is working fine. But how can I check if an object exists? For example I want to see if there is a /org/freedesktop/ConsoleKit/Session2 (just an example, I know I could enumerate all Sessions in the Seat object).
I tried using the org.freedesktop.DBus.Peer.Ping function, but that will return
dbus-send --system --print-reply --reply-timeout=2000 --type=method_call --dest=org.freedesktop.DBus /org/freedesktop/ConsoleKit/Seat1 org.freedesktop.DBus.Peer.Ping
Error org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 1 matched rules; type="method_call", sender=":1.168" (uid=1000 pid=18279 comm="dbus-send --system --print-reply --reply-timeout=2") interface="org.freedesktop.DBus.Peer" member="Ping" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)
You have several options, listed in order from most preferable to least preferable:
Enumerate all the sessions in the seat object using GetSessions().
Try and call the method you want on that session’s object path and see if it fails with an error from org.freedesktop.DBus.Error.
Call the Introspect() method on /org/freedesktop/ConsoleKit and parse the <node> elements from the resulting XML blob to see the current object path hierarchy.
The first option is probably the easiest to implement, and is how you’re intended to use the ConsoleKit API. Note that seat and session numbering is not deterministic, so you shouldn’t just hard-code a session object path in your code, since that path might change on future boots.
Also note that, as the ConsoleKit website says, ConsoleKit is deprecated in favour of systemd-logind, which you should consider using instead.
Related
I'm testing an application that calls one API, gets a bunch of work orders, then only the work order ID's are passed to another API to display on the page.
The format they need to be in is: {"workOrderIds":["12345","123456"]}
I'm using the JSON Extractor with the following Path Expressions:
$..workOrderNumber
then I'm using the JSR223 PostProcessor and using the following script:
props.put("workOrderNumber", "${workOrderNumber}";
The problem is, that its creating the object like so when I add the variable into the POST Request body of the second request:
{"workOrderIds":["12345, 123456"]}
essentially, I just need to make sure that each value has quotations, but not sure how to make this happen. Sorry if this seems simple, I'm fairly new to QA and have spent several hours trying to figure this out.
We cannot provide a comprehensive answer without seeing the source JSON, maybe it worth trying explicitly casting the filtering result to an Integer like:
vars.put('workOrderIds', new groovy.json.JsonBuilder(new groovy.json.JsonSlurper().parse(prev.getResponseData()).findResults { entry -> entry.workOrderNumber as int }).toPrettyString())
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
I am using the Sling MimeTypeService in order to get an appropriate extension for a given file & trying to override a default extension with my own.
E.g. if I had a method:
#Reference
MimeTypeService mimeTypeService;
public void getPlainTextAsDiff() {
mimeTypeService.registerMimeType("text/plain", ".diff");
mimeTypeService.getExtension("text/plain"); //returns ".txt"
}
This returns ".txt" rather than ".diff", ignoring the first line of the method.
This also seems to be inline with the documentation:
A MIME type may be mapped to multiple extensions (e.g. text/plain to
txt, log, ...). This method is expected to returned one of those
extensions. It is up to the implementation to select an appropriate
extension if multiple mappings exist for a single MIME type.
[My emphasis]
I'm wondering if it's possible to circumvent this somehow, e.g. deregistering a mime-type or ranking those available, so that in the case above "diff" would guaranteed to be returned?
You can extend mime type mappings by providing MimeTypeProvider services, but looking at the MimeTypeServiceImpl code it looks like those are not sorted by service ranking. If I'm correct, you won't have a way to prioritize you MimeTypeProviders. You might want to experiment with this and submit an enhancement request or patch.
I do a standard pattern in my application - a link to /controller/delete/object_id, then a post form to "confirm", a check if $this->request->is('post') and if true - the controller deletes the object from database.
What is weird is that for a single, particular object_id, my browser (Firefox) forces the form to be a GET one. With any other object_id everything is ok, but with this particular one, despite all declarations within form tag and etc. brower generates a GET request.
Do you have any clue what this might be?! I even tried to use brower's private mode, because I thought it can be some garbage in browser cache, but the bug is still here.
I managed to bypass this problem:
define a specific action in form->create, pointing to your controller' method
add a hidden field with object_id
add some additional code in the controller method to get object_id from $this->request->data, because a hidden post field is not passed as an argument to method, as it is with GET method.
This way, to some unknown reason, it just works. Anyway, I still feel I'm doing something wrong. It's not as "clean" as I would expect.
I'm going through Lift's basics in Section 3.2 SiteMap of Simply Lift and one thing struck me.
Using the default SiteMap code, you can ask for, say, info view in three ways:
GET /info,
GET /info.html,
GET /info.xml (why?).
What is more, you can request index view in four different ways:
GET /,
GET /index,
GET /index.html,
GET /index.xml.
How can I limit this behaviour to GET / for directories and GET /info for files?
P.S. All of these return 200 OK:
foursquare.com/,
foursquare.com/index,
foursquare.com/index.html,
foursquare.com/index.xml.
Shouldn't one resource have one URL only?
There are actually more than four ways that it can be parsed. The full list of known suffixes (any of which can be used to access the page) can be found here.
I think the reason for that is that lift can be used to serve any resource, so most are explicitly added by default.
I think you could disable Lift's processing of all extensions by adding this to Boot.scala:
LiftRules.explicitlyParsedSuffixes = Nil
However, I wouldn't recommend that as there may be some side-effects.
Using Req with RestHelper you can specify the suffix explicitly, but I don't know if there is such a construct to do so with Sitemap.
Actually, the code to determine whether Lift should handle the request or not is here. You can see the default extensions in the liftHandled method directly above, but they can all be overridden with LiftRules.liftRequest. Something like:
LiftRules.liftRequest append {
case r => Full(r.path.suffix.trim == "")
}
Should do the trick.
As far as why it works that way, Jason is right that Lift is designed to handle multiple types of dynamic resource.
I would like to set different contacts for same service based on from which host the service is called.
I've tried to use macro, but it gets translated only when command is called.
Then I've tried to edit command itself, but I think that variable CONTACTEMAIL is managed internally by icinga. I don't feel comfortable with adding only pure emails to some custom macro defined in HOST.
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Icinga *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
Did anyone try/solve this?
You can define your contact on the host and delete it from services. This way every service in that host will inherit its contacts, if you define a contact again in the service it will ignore the previous one.
If the contacts depends on each service and not host, you will have to define same service for each host/contact.
$CONTACTEMAIL$ is a macro for the contact object, referencing to the attribute "email". Your command "notify-service-by-mail" will be assigned to such a contact as "service_notification_command" and that contact assigned to a service then (or via contactgroup). So once a notification happens, all required information is available and the core will translate the macro $CONTACTEMAIL$ to the real value and pass the converted string to the shell for execution then.
I would go for 2 options
use implied inheritance (http://docs.icinga.org/latest/en/objectinheritance.html), and only define contacts for the host, and not the service below. the configuration parser will recognise that contacts should be inherited and your services will get only the related host's assigned contacts then. Though, this may get ugly in terms of not wanting to notify the host alerts to the same contacts as for the service themselves.
making this more dynamic, i.e. setting service contacts based on their hostname, i would suggest using a config (generation) tool, allowing you e.g. manipulate the service->host relation with the defined contacts then. Though, there seems not really a generic solution out there... I would give LConf a try with the ldap tree itsself, but not sure if this would work out here, rather than writing a custom script, or use some puppet magic.