You have a console.log inside a call to console.log.
I would have expressed an error but apparently it’s just calling the inner one before the outer one and since console.log doesn’t return anything the outer one logs undefined.
It should be
console.log("event.newState = "+event.newState);
As for the other undefined, not all properties are available for all rule triggers. This rule is triggered by an item change so there will never be event.receivedCommand. That will always be undefined.
The trigger for the script is core.ItemCommandTrigger so the event object won’t have a newState property, where as your first script was an core.ItemStateChangeTrigger, which will have a newState property, but not a received command property.
To provide a bit more details, from @Johnno’s correct answer, please see the table in the JS Scripting docs. It tells you which properties exist on the event Object depending on the way the rule was triggered. JavaScript Scripting - Automation | openHAB
It makes no sense to have a newState nor receivedState property on the event that was triggered by a command because a command doesn’t change the state of the Item. There is no newState yet. Only an update can change the state of an Item. There is no newState (necessarily) for an update event. There is only a newState when the Item has changed state.
You must know how the Item is triggered before accessing properties of event because only the relevant properties will be defined.
Most of time, you’ll just know because the rule only has one trigger or all the same type of triggers. However, if the rule has multiple different types of triggers, you can determine what type of trigger it was through the event.type and event.triggerType properties. And even then, those are only defined when the rule is triggered and not when the rule was called from another rule.
What are you trying to achieve with this rule? If it’s reacting to a change in PiHole, you should use a changed trigger, However, if it is running some code to make a change in PiHole, received command is appropriate. But you need to use event.receivedCommand instead of event.newState or event.receivedState.